Item(Index: Integer): Variant;
Item[Index: Integer]: Object;
Index. Index of tuple element.
The Item property returns value of tuple element with the specified index.
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 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(0) As IPythonTuple;
Debug.WriteLine(pTuple.Length);
Arr := pTuple.ToArray;
For Each v In Arr Do
Debug.Write(v + " ");
End For;
End Sub UserProc;
Imports Prognoz.Platform.Interop.Python;
Public Shared Sub Main(Params: StartParams);
Var
pUtils: IPythonUtils = New PythonUtilsClass();
pTuple: IPythonTuple = New PythonTupleClass();
Result, v: Object;
Arr: Array;
Begin
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.Create(Result);
//As the getWeekDayTuple function results in the object, the created tuple in pTuple
//will consist of one element. This element must be also cast to the IPythonTuple type to
//be able to work with separate tuple elements from the getWeekDayTuple result
pTuple := pTuple.Item[0] As IPythonTuple;
System.Diagnostics.Debug.WriteLine(pTuple.Length);
Arr := pTuple.ToArray();
For Each v In Arr Do
System.Diagnostics.Debug.Write(v + " ");
End For;
End Sub;
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: