Python - how do I call external python programs?

If you want to call each as a Python script, you can do

import subprocess
subprocess.call(["python", "myscript.py"])
subprocess.call(["python", "myscript2.py"])

But a better way is to call functions you've written in other scripts, like this:

import myscript
import myscript2

myscript.function_from_script1()
myscript2.function_from_script2()

Where function_from_script1() etc are defined in the myscript.py and myscript2.py files. See this page on modules for more information.


Check out the subprocess documentation.