Reputation: 11
How can I open one python file from another in a separate console window. I have tried using import file
, but this runs it in the same console as the original program.
Upvotes: 0
Views: 437
Reputation: 7960
You want to execute another python instance for that.
Create a list where arg[0] is the python executable path (sys.executable
).
This is like running the Python script from a command prompt or bash shell.
import subprocess, sys
script_name = 'my_other_script.py'
# set arg1, arg2, etc. to match the script arguments
cmd_line[sys.executable, script_name, arg1, arg2]
subprocess.check_call(cmd_line)
Upvotes: 1