IPythonTuple.Item

Syntax

Item(Index: Integer): Variant;

Parameters

Index. Index of tuple element.

Description

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

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 getWeekDayTuple(lang):

if lang.lower().find("rus") != -1:

return ("Mon", "Tue", "Wed", "Thur", "Fri", "Sat", "Sun")

else:

return ("Mo", "Tu", "We", "Th", "Fr", "Sa", "Su")

Add a link to the Python system assembly.

Sub UserProc;
Var
    pUtils: IPythonUtils;
    pTuple: IPythonTuple;
    Result, v: Variant;
    Arr: Array;
Begin
    pUtils := 
New PythonUtils.Create;
    pUtils.AddFolderToPythonPath(
"d:\Work\Python\");
    
//Get tuple that is a result of function execution
    Result := pUtils.Invoke("sample""getWeekDayTuple""rus");
    
//Create a tuple from obtained result of the getWeekDayTuple function
    pTuple := New PythonTuple.Create(Result);
    
//As the getWeekDayTuple function results in the object, the created tuple in pTuple
    //will consist of one element. This element must also be cast to the IPythonTuple type to
    //be able to work with separate tuple elements from getWeekDayTuple result
    pTuple := pTuple.Item(0As IPythonTuple;
    Debug.WriteLine(pTuple.Length);
    Arr := pTuple.ToArray;
    
For Each v In Arr Do
        Debug.Write(v + 
" ");
    
End For;
End Sub UserProc;

On executing the example the getWeekDayTuple Python function is executed. This function returns a tuple with short names of weekdays. The obtained tuple is transformed into a Fore array. Values of array elements are displayed in the development environment console.

See also:

IPythonTuple