Running Python in the InterSystems IRIS Terminal
Are you curious about how to run Python scripts directly in your InterSystems IRIS or Caché terminal? 🤔 Good news it's easy! 😆 IRIS supports Embedded Python, allowing you to use Python interactively within its terminal environment.
How to access the Python Shell?
To launch the Python shell from the IRIS terminal, simply run the following command:
do##class(%SYS.Python).Shell()This opens an interactive Python shell inside the IRIS terminal. From here, you can write and run Python code just as you would in a normal Python environment.
Exiting the Shell:
>>> quit()
This will exit the Python shell and return you to the ObjectScript prompt.
USER>do##class(%SYS.Python).Shell()
Python 3.9.5 (default, May 312022, 12:35:47) [MSC v.1927 64 bit (AMD64)] on win32
Type quit() or Ctrl-D to exit this shell.
>>> name = 'Vachan'
>>> age = 25
>>> print('Name: ',name,'\nAge:',age)
Name: Vachan
Age: 25
>>> quit()
This is a great way to leverage Python's capabilities within your InterSystems environment. Whether you're experimenting, testing logic, or integrating with ObjectScript, the embedded Python shell makes it fast and flexible.
Enjoy Coding! 👨💻
Comments
You can use :py alias to connect the python shell in IRIS terminal as well.
Thanks! that worked!
Thanks! It's a cool article 😄 I'm gonna try it.
If you use the InterSystems CLI vis your OS shell, you can also simply run:
#iris python instancename
See the iris command docs (at least for some OSs).