FAQ-1078 How do I write code for use interchangeably with embedded and external Python?

Last Update: 12/22/2020

The originpro Python package works almost exactly the same for the Python interpreter embedded into Origin and a Python interpreter accessing Origin externally. This means that you could write a portable script that works for both types of interpreter.

However, there are two small additions that need to be made to such a script. Those additions are illustrated in the code below. They both target originpro only when run from an external Python interpreter.

The first addition sets the visibility of the instance of Origin that launches, while the second shuts down the running instance of Origin. Simply wrap your originpro code in these two code blocks and your script can become portable between interpreters.

import originpro as op

# Set Origin instance visibility.
# Important for only external Python.
# Should not be used with embedded Python. 
if op.oext:
    op.set_show(True)


# Your originpro-based Python code goes here.


# Exit running instance of Origin.
# Required for external Python but don't use with embedded Python.
if op.oext:
    op.exit()

Keywords:Python, originpro, embedded, external, interpreter, portable, dual