%SYS.Python
class %SYS.Python extends %Library.SystemBase
Provides utilities for loading and using Python modules, running Python commands, and starting the Python shell. For information on working with Python within IRIS, see Using Embedded Python.Method Inventory
Methods
classmethod Builtins(flags As %Integer) as %CPP.LongLong
Loads the Python
builtins
module and returns a handle to that module.
On failure, this method returns 0.
Using this method is equivalent to using Import() to load the Python builtins module.
classmethod Bytes(cmd As %String) as %CPP.LongLong [ Language = cpp ]
Given an ObjectScript string, returns a Python object of type bytes.
The input string cannot contain any wide character.
classmethod False() as %CPP.LongLong [ Language = cpp ]
Returns the Python
False
value.
classmethod Import(name As %String) as %CPP.LongLong [ Language = cpp ]
Loads a Python module and returns a handle to that module. On failure, this method returns 0.
Typically you use this method to bind the module to a variable, which you then use
to call code within the module. For example:
set mypython = ##class(%SYS.Python).Import("package.subpackage.name") write mypython.helloWorld()
classmethod None() as %CPP.LongLong [ Language = cpp ]
Returns the Python
None
value.Runs one or more Python commands; to run multiple commands, separate the commands
with a new line, $char(10). This method returns 0 on success or -1 on failure.
Starts the interactive Python shell.
To use this method, you must have USE permission on the %Developer resource.
To exit the shell, type the command
quit()
classmethod ToList(contentList As %CPP.BinList) as %CPP.LongLong [ Language = cpp ]
Given contentList (an ObjectScript list),
this method returns a Python list that contains the same data. For example:
set clist = $lb(123, 456.789, "hello world") set plist = ##class(%SYS.Python).ToList(clist)
classmethod ToListTyped(contentList As %CPP.BinList, typeList As %CPP.BinList) as %CPP.LongLong [ Language = cpp ]
Given two ObjectScript lists,
returns a Python list that contains the same data as contentList,
with each member of the list having the data type specified in typeList.
For example, the following code returns a Python list where each member of the list has the value 42,
but is represented as SQL_BIT, SQL_NUMERIC, SQL_DECIMAL, and SQL_INTEGER, respectively:
set clist = $lb(42, 42, 42, 42) set tlist = $lb(-7, 2, 3, 4) set plist = ##class(%SYS.Python).ToListTyped(clist, tlist)
classmethod True() as %CPP.LongLong [ Language = cpp ]
Returns the Python
True
value.