IPythonTuple.Length

Syntax

Length: Integer;

Description

The Length property returns tuple length.

Example

Executing the example requires a folder with modules: d:\Work\Python\. The folder contains the sample.py module. The following function is implemented in the module:

def getSizeOfList(l):

return l.__sizeof__()

Add a link to the Python system assembly.

Sub UserProc;
Var
    pUtils: IPythonUtils;
    pList: IPythonList;
    pTuple: IPythonTuple;
    Result: Variant;
Begin
    pUtils := 
New PythonUtils.Create;
    pUtils.AddFolderToPythonPath(
"d:\Work\Python\");
    
//Create list and tuple
    pList := New PythonList.Create(0"A", Char.Chr(169)); //169 code of the © sign
    pTuple := New PythonTuple.Create(0"A", Char.Chr(169)); //169 code of the © sign
    //Get information about list
    Result := pUtils.Invoke("sample""getSizeOfList", pList);
    Debug.WriteLine(
"Number of elements in list: " + pList.Length.ToString);
    Debug.WriteLine(
"Size of memory used (bites): " + Result);
    
//Get information about tuple
    Result := pUtils.Invoke("sample""getSizeOfList", pTuple);
    Debug.WriteLine(
"Number of elements in the list: " + pTuple.Length.ToString);
    Debug.WriteLine(
"Size of memory used (bites): " + Result);
End Sub UserProc;

On executing the example the objects that contain a Python list and tuple are created. Each object will be sent to the getSizeOfList function to get size of the memory it occupies. The number of list and tuple elements, and size of occupied memory are displayed in the development environment console.

See also:

IPythonTuple