IPythonList.Item

Syntax

Item(Index: Integer): Variant;

Parameters

Index. List element index.

Description

The Item property returns value of list element with the specified index.

Example

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

import random

def getNewList(count):

res = []

i = 0

while i < count:

res.append(random.uniform(0, 100))

i = i + 1

return res

Add a link to the Python system assembly.

Sub UserProc;
Var
    pUtils: IPythonUtils;
    pList: IPythonList;
    Result, v: Variant;
    Arr: Array;
Begin
    pUtils := 
New PythonUtils.Create;
    pUtils.AddFolderToPythonPath(
"d:\Work\Python\");
    
//Get a list which is a result of the function execution
    Result := pUtils.Invoke("sample""getNewList"10);
    
//Create a list from obtained result of the getNewList function
    pList := New PythonList.Create(Result);
    
//As the getNewList function result is an object, the list created in pList
    //will contain one element. This element must be cast to the IPythonList type, in order
    //to work with separate elements from the list from the getNewList result
    pList := pList.Item(0As IPythonList;
    Debug.WriteLine(pList.Length);
    Arr := pList.ToArray;
    
For Each v In Arr Do
        Debug.Write(v + 
", ");
    
End For;
End Sub UserProc;

On executing the example the getNewList Python function is executed. This function returns a list with random numbers. The obtained list will be transformed into a Fore array. Values of array elements are displayed in the development environment console.

See also:

IPythonList