Length: Integer;
Length: Integer;
The Length property returns tuple length.
Executing the example requires a folder with units: d:\Work\Python\. The folder contains the sample.en unit. The following function is implemented in the unit:
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;
Imports Prognoz.Platform.Interop.Python;
Public Shared Sub Main(Params: StartParams);
Var
pUtils: IPythonUtils = New PythonUtilsClass();
pList: IPythonList = New PythonListClass();
pTuple: IPythonTuple = New PythonTupleClass();
Result: Object;
Begin
pUtils.AddFolderToPythonPath("d:\Work\Python\");
//Create a list and tuple
pList.Create(0, "A", Char.ConvertFromUtf32(169)); //169 code of the © sign
pTuple.Create(0, "A", Char.ConvertFromUtf32(169)); //169 code of the © sign
//Get information about the list
Result := pUtils.Invoke("sample", "getSizeOfList", pList);
System.Diagnostics.Debug.WriteLine("Number of elements in the list: " + pList.Length.ToString());
System.Diagnostics.Debug.WriteLine("Size of memory used (bites): " + Result);
//Get information about tuple
Result := pUtils.Invoke("sample", "getSizeOfList", pTuple);
System.Diagnostics.Debug.WriteLine("Number of elements in the list: " + pTuple.Length.ToString());
System.Diagnostics.Debug.WriteLine("Size of memory used (bites): " + Result);
End Sub;
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: