Daniel Mohammed Daniel Mohammed - 1 year ago 115
Python Question

How to open a Python 3 Program in another folder within Python 3

I would like to open a Python 3 program within Python 3, but the target program is in another folder.

EG: Pythonloader.py > PythonFolder > Target.py

I am using Python 3.3.0

Answer Source

Use the subprocess module to run any external program:

import subprocess
subprocess.call('python3 /path/to/target.py')

Check https://docs.python.org/2/library/subprocess.html for a review.

If you want to import the code to use within your script:

import sys
import target

Then you can use the code within.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download