Hao Ma · Nov 29, 2019

How to execut code in local .py file in python gateway?

who has tried "python gateway" in OpenExchange, could you please tell me how to  execute code in a local .py file? a cusotmer engineer ask me the question while I don't have time to study it yet. Thank you very much. 

0 310
Discussion (3)2
Log in or sign up to continue

This should work for Python Gateway:

set filename = "/path/to/"
set file = ##class(%Stream.FileCharacter).%New()
set sc = file.LinkToFile(filename)
set sc = ##class(

In addition to Eduard's answer, a short example based on sending Python's exec command to Python (assuming Python 3.*) to execute a Python script stored in a file:

(1)  Create a in some folder that Python has access to, add the following lines to

print('Hello Python Gateway',file=f)

Save and close

(2)  Open  IRIS Terminal, type and execute one by one the following commands:

set sc=##class(

set sc=##class("exec(open('disk:/path/to/your/folder/').read())",,,.sc)

(3) Check the output.txt file that has been created in your folder

Note that instead of:

do ##class(

Python Shell can be entered by simply typing


In there you can just directly type python code:


Or don't open the shell and call:

set sc=##class("exec(open('disk:/path/to/your/folder/').read())",,,.sc)