I have a genetic expression tree program to control a bot. I have a GP.py and a MyBot.py. I need to be able to have the MyBot.py access an object created in GP.py
The GP.py is starting the MyBot.py via the os.system() command
I have hundreds of tree objects in the GP.py file and the MyBot.py needs to evaluate them.
I can't combine the two into one .py file because a fresh instance of MyBot.py is executed thousands of times, but GP.py needs to evaluate the fitness of MyBot.py with each tree.
I know how to import the methods and Class definitions using import GP.py, but I need the specific instance of the Tree class object
Any ideas how to send this tree from the first instance to the second?
You could serialize the object with the pickle module (or maybe json?)
If you really want to stick with os.system, then you could have MyBot.py write the pickled object to a file, which GP.py could read once MyBot.py returns.
If you use the subprocess module instead, then you could have MyBot.py write the pickled object to stdout, and GP.py could read it over the pipe.
If you use the multiprocessing module, then you could spawn the MyBot process and pass data back and forth over a Queue instance.
How to pass object between python instances