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
Comments
What’s the point of using Python and attempting to keep using ObjectScript functions, find python alternatives
Python can do multithreading, do you can process in background
This was related to OwnObjectScriptExtension. It has a nice feature of converting ObjectScript to Python. It converts quite nice but gets stuck with such special variables.
If I find no acceptable equivalent in PY
I wrap such functions, methods, variables, ... in 1 line COS (class)methods.
kind or embedded COS 😏
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'Thanks a lot, @Alex Woodhead !
@Philipp Bonin , maybe you could consider that in your wonderful ObjectScript to Embedded Python translator?
Thanks, @Alex Woodhead !
What about $objproperty and $objmethod?
The first one could be really helpful
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