Question
· Jun 19, 2023

How do I use $znspace and Other $Functions and $Variables in Embedded Python?

Hi folks!

Just curious, how can I use $znspace in embedded python code?

How does other $functions work, e.g. $zv, $job, etc

Product version: IRIS 2023.1
Discussion (7)2
Log in or sign up to continue

After a bit of digging I came up with the following equivalents.

$Horolog

>>> iris.cls("%SYSTEM.SYS").Horolog()
'66647,85547'

Equivalent access:

>>> var=iris.cls("%Library.UTC").NowLocal()
>>> var
'2023-06-22 23:50:04.386'
>>> iris.cls("%Library.UTC").ConvertTimeStampToHorolog(var)
'66647,85804.386'

$NAMESPACE ($ZNSPACE)

>>> iris.cls("%SYSTEM.SYS").NameSpace()
'USER'

ZN [Namespace] - aka change namespace

Keep your object fingers in the car at all times!!

Any created object script references need to be cleared BEFORE changing back. Is it necessary.

>>> iris.cls("%SYSTEM.Process").SetNamespace("%SYS")
'%SYS'

$JOB

>>> iris.cls("%SYSTEM.SYS").ProcessID()
'1548'

$SYSTEM - Instance name

>>> iris.cls("%SYS.System").GetInstanceName()
'IRIS123'

But you might have same name on different operating system / container so:

>>> iris.cls("%SYS.System").GetUniqueInstanceName()
'THEMACHINE.YOURDOMAIN.COM:IRIS123'

$ZTIMESTAMP

>>> iris.cls("%SYSTEM.SYS").TimeStamp()
'66647,81615.3832864'

$ZTIMEZONE – Contains the time zone offset from the Greenwich meridian

>>> iris.cls("%SYSTEM.SYS").TimeZone()
0

$ZVERSION – Contains a string describing the current version of InterSystems IRIS

>>> iris.cls("%SYSTEM.Version").Format(0)
'IRIS for Windows (x86-64) 202x.x.0 (Build xxU) Thu xx 2023 06:22:16 EDT'

Hi Evgeny,

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

$Classmethod equivalent

classname="%SYSTEM.SYS"
methodname="ProcessID"
eval(f"iris.cls(\"{classname}\").{methodname}()")

$Property equivalent

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

myerror=iris.cls("%Exception.PythonException")._New("MyOops",123,"def+123^XYZ","SomeData")

for propertyname in ["Name","Code","Data","Location"]:
    propvalue=eval(f"myerror.{propertyname}")

    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