0

Originally I had two scripts main.py and call_main.py They were in the same level.

In call_main.py I had

import subprocess

cmd = [
        "python3",
        "main.py",
]
subprocess.run(cmd)

No problem there. However now I am moving the call_main.py script two levels deeper to a folder /tools/mytools/call_main.py

How should I modify the script to be able to call main.py?

In the beginning I tried changing the call to

import subprocess

cmd = [
        "python3",
        "../../main.py",
]
subprocess.run(cmd)

and changing any parameters that I call accordingly,

However it seems main.py call other scripts so when I do the above way, it cannot file some imports it does.

So any good way to be able to run main?

KansaiRobot
  • 7,564
  • 11
  • 71
  • 150
  • Running Python as a subprocess of itself is often an antipattern. A better solution is to `import` the code you want to run (you might have to refactor it to make this possible). – tripleee Feb 03 '23 at 08:47
  • Unfortunately, that is not something I can question in the present situation – KansaiRobot Feb 03 '23 at 12:09

0 Answers0