Skip to main content

%SYS.Python

class %SYS.Python extends %Library.SystemBase [ Final ]

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 PythonOpens in a new tab.

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.
classmethod Run(cmd As %String) as %Integer [ Language = cpp ]
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.
classmethod SetInteractiveMode(state As %Integer) as %Integer
Set the mode of python to Interactive meaning that signal handling state swaps will be allowed. Interactive mode has a performance cost, but enables useful features like saving/restoring terminal state and generating better documentation. Returns previous signal state: 0 - swapping allowed, 1 - swapping disabled, -1 - Swapping unapplicable to your platform.
classmethod Shell(vars As %Integer = 0) as %Status
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 listOpens in a new tab), 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 listsOpens in a new tab, 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.

Inherited Members

Inherited Methods

FeedbackOpens in a new tab