Import python libraries

Thanks Tate! Dion - What Tate wrote is generally the best way to do it.

Your other options:

  • If you don’t need a return value from your outside Python, use Ignition’s system.util.execute()
  • If you do need a return value, you can get fancy and call Java’s executor Runtime.getRuntime().exec(cmd), and then get the string output value from that.

As mentioned, Bottle or Flask are going to be more robust and cleaner than doing an execute() / exec(), so go that route if you can.

Bottle example:

from bottle import route, run

@route('/hello')
def hello():
    return "Hello World!"

run(host='localhost', port=8080, debug=True)

This example serves out the responses to http://localhost:8080/hello

1 Like