Daniel Mohammed Daniel Mohammed - 1 month ago 10
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

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
sys.path.append('/path/to/containing/directory')
import target

Then you can use the code within.

Comments