IPythonDictionary.Item

Syntax

Item(Key: Variant): Variant;

Parameters

Key. Value key.

Description

The Item property returns the value with the specified key.

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 getNewDictionary(count):

d = {a: a ** 2 for a in range(count)}

return d

Add a link to the Python system assembly.

Sub UserProc;
Var
    pUtils: IPythonUtils;
    pDict: IPythonDictionary;
    Result, Key: Variant;
    KeyList: IPythonList;
    i, c: Integer;
Begin
    pUtils := 
New PythonUtils.Create;
    pUtils.AddFolderToPythonPath(
"d:\Work\Python\");
    
// Get dictionary that is a result of function execution
    Result := pUtils.Invoke("sample""getNewDictionary"10);
    
// Create a dictionary from obtained result of the getNewDictionary function
    pDict := New PythonDictionary.Create(Result);
    KeyList := pDict.Keys;
    c := pDict.Length;
    
// View existing key-value pairs
    For i := 0 To c - 1 Do
        Key := KeyList.Item(i);
        Debug.WriteLine(
"Key: " + Key + "; Value: " + pDict.Item(Key));
    
End For;
End Sub UserProc;

After executing the example the getNewDictionary Python function will be executed. This function returns the generated dictionary with ten key-value pairs. The obtained keys and values will be displayed in the development environment console.

See also:

IPythonDictionary