IPythonClassObject.GetAttr

Syntax

GetAttr(AttrName: String): Variant;

Parameters

AttrName. Class argument name. The name is case-sensitive.

Description

The GetAttr method gets values of the argument with the specified name from class instance.

Comments

If the class instance does not contain an argument named AttrName, an exception is thrown.

Example

Executing the example requires a folder with modules: d:\Work\Python\. The folder contains the sample.py module. The following class is implemented in the module:

class Door:

def __init__(self, color, height, width):

self.color = color

self.height = height

self.width = width

def getDoorDescription(self, comment):

return comment + ". Color: " + self.color + " Size: " + str(self.height) + "X" + str(self.width) + " mm"

Add a link to the Python system assembly.

Sub UserProc;
Var
    pUtils: IPythonUtils;
    pObj: IPythonClassObject;
    Result: Variant;
Begin
    pUtils := 
New PythonUtils.Create;
    pUtils.AddFolderToPythonPath(
"d:\Work\Python\");
    
//Create object of the Door class
    pObj := New PythonClassObject.Create("sample""Door""Red"2000800);
    
//Get value of the color attribute
    Result := pObj.GetAttr("color");
    Debug.WriteLine(Result);
    
//Change value of the color attribute
    pObj.SetAttr("color""White");
    
//Execute function of the class instance
    Result := pObj.Invoke("getDoorDescription""Connecting door");
    Debug.WriteLine(Result);
End Sub UserProc;

The following operations are executed on starting the example:

  1. An instance of the Door class is created. The constructor sends values of parameters that will be assigned to attributes.

  2. Value of the "color" attribute is obtained for the created object. The value is displayed in the development environment console.

  3. The new value is set for the "color" attribute.

  4. The function of the getDoorDescription class instance is executed, the obtained result is displayed in the development environment console.

See also:

IPythonClassObject