Reputation: 719
I want to use a python2 module from python3. My idea was to have the python2 work in it's file, then use the subprocess module from python3 with args (to Popen) being ["python2", "script.py"]
. The methods provided return all strings. Is it possible to also capture data structures directly from the running process, for instance if I have generated a final dictionary in the script.py and I want to get that dictionary Object as the result of the computations in script.py. Any helps would be appreciated.
Upvotes: 1
Views: 159
Reputation: 207425
You could serialize your dict to a JSON in Python2 and load the JSON in Python3. There is an example here.
Rather than pollute the filesystem with unnecessary writes and files, you could just print the JSON on stdout
in your Python 2 script and then read it as the output from subprocess()
in your Python 3 script. That will depend on your local environment.
Upvotes: 2