· Jun 25

What is the Synonym of $property for Embedded Python?

Hi folks!

I have a need to use symilar to $property function from Python. Here is the code:


for property, value in data.items():

 $property( ; I invented this

How could I do this? Any trick?

For now I plan to implement a helper function in iris that I will call, but I doubt also how can I transfer oref to IRIS.


Discussion (5)2
Log in or sign up to continue

Hi Evgeny,

Not saying this is best way but this indirection can be achieved with python eval. For example:

$Classmethod equivalent


$Property equivalent

Instantiating a Python exception and then iterate over properties printing out name and value:


for propertyname in ["Name","Code","Data","Location"]:

    print(f"Property Name {propertyname} has value {propvalue}\n")

output was:

Property Name Name has value MyOops
Property Name Code has value 123
Property Name Data has value SomeData
Property Name Location has value def+123^XYZ

And for completeness: setting a property with a name not known until runtime can be done with the counterpart of getattr, setattr:

USER>do ##class(%SYS.Python).Shell()

Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] on linux
Type quit() or Ctrl-D to exit this shell.
>>> e=iris.cls("%Exception.PythonException")._New("MyOops",123,"def+123^XYZ","SomeData")
>>> e.Name
>>> setattr(e,'Name','TheirOops')
>>> e.Name