Question
Evgeny Shvarov · Oct 6, 2022

What is the Analog of $DATA for Embedded Python?

Hi folks!

I'm working with a global via Embedded Python as a class method. I init the handler for a global via:

gl=iris.gref("^Global")

What is the way to check the value at index ^Global("x","y")? E.g.:

In ObjectScript I'd do the following:

set result=$data(^Global("x","y"))

How do I do the same in Embedded Python?

I checked the documentation, but haven't found an answer.

Product version: IRIS 2022.1
2
0 133
Discussion (4)2
Log in or sign up to continue

in my package GlobalToJSON-ePython-pure
I developed this workaround: 

#; simulate $data() for existence and content
def Ddata(gref):
	val = None
	_d = 11
#; check for subscripts	
	o=gref.order([])
	if o == None:
		_d -= 10
	try:
		val=gref.get([])
	except KeyError:
		#; no value @ top node
		_d -= 1
	return [_d,val]		

There's a method on the iris.gref class called "data".

set ^zJES(1)="$data = 1"
set ^zJES(2,0)="$data = 10"
set ^zJES(4) = ""
set ^zJES(4,0) = ""

The result ends up matching $data:

>>> glb = iris.gref("^zJES") 
>>> print(glb.data())
10
>>> print(glb.data([1])) 
1
>>> print(glb.data([2]))
10
>>> print(glb.data([3]))
0
>>> print(glb.data([4]))
11

I found running help(iris) at the Python shell helpful for working this kind of stuff out.

Edit: Unlike @Robert Cemper's solution this does not return the value of the node we're testing (like the 2 parameter usage $data)