How to change namespace from embedded python?
Hi,
I am getting below error while using embedded python script.
.png)
Want to know how can I change namespace to %SYS to use above mentioned class?
Thanks
Comments
just do it in a classMethod in Objectscript
don't forget to return to your original namespace to find where you came from
For now, it's not possible in pure python, because the select namespace is specified by the environment variable IRISNAMESPACE, and environment variable can't be change in the parent process, I have tried by reloading iris module with no success.
To achieve that, for now, as Robert says, you have to create an helper method in objectscript ... :(
Class Embedded.Utils
{
ClassMethod GetNameSpace() As %Status
{
Return $namespace
}
ClassMethod SetNameSpace(pNameSpace) As %Status
{
zn pNameSpace
Return $namespace
}
}
Python :
import iris
print(iris.cls("Embedded.Utils").GetNameSpace())
try:
print(iris.cls("Security.Users").Exists("SuperUser"))
except RuntimeError:
print("Wrong NameSpace")
print(iris.cls("Embedded.Utils").SetNameSpace("%SYS"))
try:
print(iris.cls("Security.Users").Exists("SuperUser"))
except RuntimeError:
print("Wrong NameSpace")
Thanks @Guillaume Rongier
But be aware to have the method SetNamespace available also the new target namespace to be able to return !
So you either map the class to Namespace %All,
or name the class %ZEmbedded.Utils or similar, to make it available across all namespaces.
About that...
Thanks Mr Robert for sharing the details
Sorry. it just turned out that sharing across namespaces doesn't (yet?) work with embedded Python
In IRIS for UNIX (Ubuntu Server LTS for x86-64 Containers) 2025.1 (Build 204U) Thu Feb 13 2025 16:06:36 EST, the following worked for me:
import iris
iris.execute('ZN "IRISAPP"')IRIS 2025.3.CE
ClassMethod test() [ Language = python ]
{
import iris
ns = iris.system.Process.NameSpace()
try:
iris.system.Process.SetNamespace('%SYS')
passenger = iris.SYS.Stats.Dashboard.Sample()
print(passenger.GloRefsPerSec)
finally:
iris.system.Process.SetNamespace(ns)
}PS: Do I need a separate python iris connection for each Namespace?