IPythonList.Add

Syntax

Add(Item: Variant);

Parameters

Item. The value that will be added to the list.

Description

The Add method adds the specified value to the list.

Comments

Python lists may contain different types of values that is why the Add method can be used to add both simple type values and various objects that are Python class instances to the list.

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;
    Result: Variant;
Begin
    pUtils := 
New PythonUtils.Create;
    pUtils.AddFolderToPythonPath(
"d:\Work\Python\");
    
//Create a list
    pList := New PythonList.Create(0"A", Char.Chr(169)); //169 code of the © character
    //Get information about the list
    Result := pUtils.Invoke("sample""getSizeOfList", pList);
    Debug.WriteLine(
"Number of elements in the list: " + pList.Length.ToString);
    Debug.WriteLine(
"Size of memory used (bytes): " + Result);
    
//Add elements
    pList.Add(Integer.MinValue);
    pList.Add(Double.MaxValue);
    pList.Add(DateTime.Now.ToString);
    
//Get information about the list again
    Result := pUtils.Invoke("sample""getSizeOfList", pList);
    Debug.WriteLine(
"Number of elements in the list: " + pList.Length.ToString);
    Debug.WriteLine(
"Size of memory used (bytes): " + Result);  
End Sub UserProc;

On executing the example an object containing a Python list is created. The list is sent to the getSizeOfList function to get RAM size that it occupies. After this several elements are added to the list, and the getSizeOfList function is called again. The number of elements and size of occupied RAM after creating and adding new elements are displayed in the development environment console.

See also:

IPythonList