Written by

Senior Startups and Community Programs Manager at InterSystems Corporation
Question Evgeny Shvarov · Oct 2, 2022

How to Refer to a Class Parameter in Embedded Python?

Hi, devs!

In ObjectScript I can refer to a class parameter as:

write ..#ParameterName

How do I do the same in Embedded Python?

Product version: IRIS 2022.1

Comments

Bob Kuszewski · Oct 5, 2022

Parameters aren't available in embedded python.  An easy workaround is to create a Property that reflects the parameter or to create an objectscript method to return the parameter.

I'm curious about the use case.

0
Evgeny Shvarov  Oct 5, 2022 to Bob Kuszewski

Thanks, @Bob Kuszewski!

The use case is the usage of class parameters in Embedded Python. They could same useful as they are in ObjectScript.

The reason to code with Embedded python as a first class citizen coding language as ObjectScript is.

0
Evgeny Shvarov  Oct 6, 2022 to Bob Kuszewski

Thought more about the use case:

The use case is “Better Developer Experience”.

0
Ben Spead  Oct 6, 2022 to Evgeny Shvarov

Well put Evgeny!  I have frequently accessed parameters from within ObjectScript and as Python is a full first class citizen alongside ObjectScript then we need to be able to access parameters from within Python as well.

0
Evgeny Shvarov  Oct 6, 2022 to Eduard Lebedyuk

This works:

print(iris.cls('ClassName')._GetParameter("ParameterName")
0
Ben Spead  Oct 6, 2022 to Evgeny Shvarov

excellent!! thanks for confirming!

0
Jose-Tomas Salvador  Oct 27, 2022 to Evgeny Shvarov

Right. But we should have a quicker way to get the parameter in our Python code.

Replacing

set r = ..#MYPARAM

with

r = iris.cls('MyPackage.Subpackage.ClassName')._GetParameter('MYPARAM') 

doesn't seem too "developer friendly" to me wink

By the way, it varies if we're in a ClassMethod or in an instance Method. In instance we could do:

r = self._GetParameter('MYPARAM') 

which it's more acceptable...

But, in a classmethod it seems that our only chance would be the long version.

I wonder if we could translate them to Python as read-only special properties, adopting perhaps some convention in their name to avoid the conflicts in the (unusual) case that there is a parameter with same name that a property.

0
Evgeny Shvarov  Oct 27, 2022 to Jose-Tomas Salvador

Yes, @Jose-Tomas.Salvador , this was my point.

But 

r = iris.cls('MyPackage.Subpackage.ClassName')._GetParameter('MYPARAM'

Can be converted to:

r = iris.cls(__name__)._GetParameter('MYPARAM'

if you are in the same class.
 

0