Biting my teeth on a problem right now:
I would like to have a py (Slave.py - which is quite complex and already finished) start / run by another py (Master.py) in the Python IDLE several times, with Slave.py always being completely restarted. This means that all variables and imports etc. there are reinitialized with each start. Each time the Slave.py is restarted, different variable values should be transferred from the Master.py to the Slave.py (the background is that the Slave.py requires a running time of 1 to 12 hours and the AI does not remain stable over several runs with changed parameters.) I work in WIN10 with the Python IDLE and have Python 3.8.3.
Found something that at least executes the Slave.py in the IDLE:
(What is an alternative to execfile in Python 3?)
with open ("Slave_01.py") as f:
code = compile (f.read (), "Slave_01.py", 'exec')
exec (code)
The problem remains for me to transfer variables from the Master.py to the Slave.py. I think you can write in the Master.py for example:
global_vars = {"Wert1": "Ford", "Wert2": "Mustang", "Wert3": 1964}
local_vars = {"Wert1": "VW", "Wert2": "Käfer", "Wert3": 1966}
with open ("Slave.py") as f:
code = compile (f.read (), "Slave.py", 'exec')
exec (code, global_vars, local_vars)
My question now is how do you resume the variable values in the Slave.py? Thanks for suggestions, how one could specifically write that.