Question
· Jun 27, 2023

Type conversion from Python List to IRIS %List

Has anyone come across a good using Embedded Python to convert a Python List object to an IRIS %List object?

My use case is I want to open an SQL entry with an Objectscript class method, then pass some information from that row into a separate Python class method which will then create a Python List object, then have the Python class method return that list back to the Objectscript class method in such a way that the Python List can be converted to an IRIS %List object for me to then use in the Objectscript code.

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

Hi Robbie,

I had created a OpenExchange PythonHelper : https://openexchange.intersystems.com/package/PyHelper

// Create an IRIS List turn into a Python List
set pyList=##class(alwo.PyHelper).toPyListOrString($LB(1,2,3,4,5,6))
// Write to terminal to check content
zw pyList
pyList=3@%SYS.Python  ; [1, 2, 3, 4, 5, 6]  ; <OREF>
// Convert the Python List to a IRIS List
set myIRISList=##class(alwo.PyHelper).ListFrompyList(.pyList)
// Output to terminal to confirm
zw myIRISList
myIRISList=$lb(1,2,3,4,5,6)

Any feedback welcome.

You can send the List by reference to the Python method, populate it inside the method and use the populated list from the objectscript who call it.

Something like this:

set listOfStrings = ##class("%Library.ListOfDataTypes").%New()
do ..TestPython(listOfStrings)
$$$TRACE("What a beautiful trace! There are "_listOfStrings.Count()_" element(s)")
...
...
ClassMethod TestPython(ByRef listOfStrings As %List) [ Language = python ]
{

	import iris
	
	
	listOfStrings.Insert("One")
	listOfStrings.Insert("Two")
	listOfStrings.Insert("Three")
	
	return 1
}