Question
· Sep 3

Undefined IRIS attribute in Embedded Python

Hi Guys,

I'm a newbie in Python and I've imported this class from another IRIS and for some reason its get an error on %ToJSON()?

I'm also wondering on the need of importing iris at the top given that this code is already running in IRIS!? 

Thanks

Product version: IRIS 2024.1
Discussion (3)2
Log in or sign up to continue

The error with the %ToJSON() method in your Python code might be due to differences in how JSON manipulation is performed across InterSystems IRIS and Python environments. In IRIS Embedded Python, dynamic objects are handled differently. You might need to ensure that the object you are calling %ToJSON() on is compatible with dynamic object functionality. For instance, IRIS provides %DynamicObject and %DynamicArray classes which facilitate JSON conversions via methods like %ToJSON(). You can interact with these classes directly and call _ToJSON() for the equivalent functionality in Embedded Python [1][2][3].

Regarding importing the iris module at the top: The iris Python package is necessary for accessing ObjectScript elements, InterSystems IRIS APIs, classes, globals, and SQL statements via Python. It provides a bridge between Python and the IRIS environment, allowing both ObjectScript and Python code to interact seamlessly. This is why it is always imported, even when working within an IRIS context from Python [4][5].

For more about bridging ObjectScript and Python, you can refer to comprehensive documentation about the iris module and Python interaction with IRIS [5].

Sources: