I have a couple of python scripts that need to be ran from the main script. Each script is written as stand alone code. I don't want to use the import statement to bring the scripts into the main scripts as I'm concerned that there may be clashes between the variables, classes, etc.
I've researched how to call scripts and tried exec(open("Motor.py").read())
, but this doesn't pause the calling script, but does run the called (Motor.py)script.
I've also tried result = subprocess.run(["python", "Motor.py"], capture_output=True, text=True)
, which bombs out the called script with syntax errors that don't exist when the called script is executed by the exec command or when the script is ran as stand alone. Here is an example of what 'errors' are returned.
CompletedProcess(args=['python', 'Motor.py'], returncode=1, stdout='', stderr=' File "Motor.py", line 68\n self.geometry(f"{750}x{385}")\n ^\nSyntaxError: invalid syntax\n')
Obviously I'm not doing something correct, but I can't figure it out. Currently coding it in python 3.
Try using the subprocess module and Popen, which will open a process you can await for.
import subprocess
cmd = [sys.executable, 'Motor.py']
subprocess.Popen(cmd).wait()