IPythonClassObject.GetAttr

Syntax

GetAttr(AttrName: String): Variant;

GetAttr(AttrName: String): Object;

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 units: d:\Work\Python\. The folder contains the sample.en unit. The following class is implemented in the unit:

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;

Imports Prognoz.Platform.Interop.Python;

Public Shared Sub Main(Params: StartParams);
Var
    pUtils: IPythonUtils = 
New PythonUtilsClass();
    pObj: IPythonClassObject = 
New PythonClassObjectClass();
    Result: Object;
Begin
    pUtils.AddFolderToPythonPath(
"d:\Work\Python\");
    
//Create object of the Door class
    pObj.Create("sample""Door""Red"2000800);
    
//Get value of the color attribute
    Result := pObj.GetAttr("color");
    System.Diagnostics.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");
    System.Diagnostics.Debug.WriteLine(Result);
End Sub;

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