IPythonSet.Add

Syntax

Add(Value: Variant);

Parameters

Value. Value added to a set.

Description

The Add method adds the specified value to a set.

Comments

If the set already has an element with the specified value, but a new element is not added.

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 unionSets(set1, set2):

return set.union(set1, set2)

Add a link to the Python system assembly.

Sub UserProc;
Var
    pUtils: IPythonUtils;
    pSet1, pSet2, pSet3: IPythonSet;
    Result, v: Variant;
    Arr: Array;
Begin
    pUtils := 
New PythonUtils.Create;
    pUtils.AddFolderToPythonPath(
"d:\Work\Python\");
    
// Create sets
    pSet1 := New PythonSet.Create("A""B""C");
    Debug.WriteLine(
"Set 1: " + pSet1.Length.ToString);
    pSet2 := 
New PythonSet.Create("B""C""D");
    Debug.WriteLine(
"Set 2: " + pSet2.Length.ToString);
    
// Call function for uniting sets
    Result := pUtils.Invoke("sample""unionSets", pSet1, pSet2);
    
// Create a set from result of the unionSets function work
    pSet3 := New PythonSet.Create(Result);
    pSet3.Add(
"E");
    pSet3.Pop;
    Debug.WriteLine(
"Set 3: " + pSet3.Length.ToString);
    Arr := pSet3.ToArray;
    
For Each v In Arr Do
        Debug.Write(v + 
" ");
    
End For;
    Debug.WriteLine(
"");
End Sub UserProc;

After executing the example two objects are created that are Python sets. These sets will be sent to the unionSets function for union. Another element will be added to the obtained set, and the first element will be removed. After that, the obtained set will be converted into an array, array elements will be displayed in the development environment console.

See also:

IPythonSet