So I've seen lots of ideas that sort of answer this question, but in all solutions, it's the first script calling the other and running it itself. Is there a way to have one python script cause another script to run independently?
Asked
Active
Viewed 110 times
0
-
Possible duplicate of [How can I make one python file run another?](https://stackoverflow.com/questions/7974849/how-can-i-make-one-python-file-run-another) – Dharmesh Fumakiya Jun 02 '19 at 10:42
-
Use REST API call. Define HTTP endpoint using flask or any other framework. Call REST API Endpoint from one script. If you mean simply calling another script from python `exec(open("another.py").read());` – BetaDev Jun 02 '19 at 10:43
-
You can use `subprocess` in your current script like: `import subprocess subprocess.call("other_script.py", shell=True)` – nj2237 Jun 02 '19 at 10:46
-
@NiranjhanaNarayanan, some systems either have a broken .py file association or default to opening in a text editor or IDE. I would first try `"py other_script.py"` and handle `FileNotFoundError` via `"python other_script.py"`. The py launcher tries to handle a shebang line in a script, given it needs a particular version or virtual environment. The fallback to "python" will probably use the current interpreter since `CreateProcess` searches the application directory first. Neither option needs or should use `shell=True`. – Eryk Sun Jun 02 '19 at 11:40