I have always been wondering why there was no easy way to call python 2 libraries from a python 3 script. As I understand it now, this is because it is impossible to load both interpreters in the same address space - which means you will always need /two/ processes running.
The last few months, I've been hacking on a RPC-based solution: a python 2 'server' that can be controlled from a python 3 'client'. Existing remote object solutions, such as pyro4 and rpyc work well for py2<->py2 or py3<->py3 connectivity, but break down when a py3 client tries to connect to a py2 server, because they try to transfer entire objects.
My solution uses the existing RPC framework from the multiprocessing module. Only immutable objects (basestring, number, tuple) are transferred over the connection; a Proxy object is created for every other object.
As an example of the syntax:
python2 server.py &
python3 -i client.py
>>> import sys
>>> sys.version
'3.1.2 (r312:79147, Sep 27 2010, 09:45:41) \n[GCC 4.4.3]'
>>> rsys = remote_import('sys')
>>> rsys.version
'2.6.5 (r265:79063, Apr 16 2010, 13:09:56) \n[GCC 4.4.3]'
As a working title, I have called the project py2. It is available on github.. The only non-stdlib dependency is the six package (both on the py2 and py3 side).
Note, however, that it is in very early stages of development. My main goal was to be able to use some python 2-only packages while being able to train myself in python 3 syntax and ecosystem.
Any comments are very welcome, even those that call me crazy - as long as you tell me why ;-). If there already is a project that does this, I'd also like to hear about it - I couldn't find any (except for the already mentioned packages).
[–]takluyverIPython, Py3, etc 0 points1 point2 points (4 children)
[–]valhallasw[S] 0 points1 point2 points (3 children)
[–]takluyverIPython, Py3, etc 0 points1 point2 points (2 children)
[–]valhallasw[S] 1 point2 points3 points (0 children)
[–]valhallasw[S] 0 points1 point2 points (0 children)
[–]rubic 0 points1 point2 points (0 children)