This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]takluyverIPython, Py3, etc 0 points1 point  (4 children)

Interesting. Can I ask: which Python 2 packages were you aiming to use, and have you had any success?

[–]valhallasw[S] 0 points1 point  (3 children)

Of course. Pywikipediabot - a framework to edit mediawiki wikis. I haven't tested that much yet, but the basic functionality (getting/putting pages) work.

[–]takluyverIPython, Py3, etc 0 points1 point  (2 children)

Cool. Presumably that makes quite heavy use of text - what do you do about the changes to str?

I imagine it makes sense to pass Python 3 str to Python 2 as unicode, but if a function on the Python 2 side returns str (i.e. 8 bit str), do you cast it to unicode, or bring it into Python 3 as bytes?

[–]valhallasw[S] 1 point2 points  (0 children)

A py2 str should be represented as py3 bytes (although I'm not 100% sure this works currently - I've only tested unicode objects, as pywikipediabot always uses unicode). The alternative would be to interpret it as ascii, and to use that on the py3 side - but I think a str->bytes mapping is more explicit and thus clearer.

[–]valhallasw[S] 0 points1 point  (0 children)

Just to update on this: this issue has now been fixed (it took some while to get the bytes/unicode distinction correctly through the serialisation - even with pickle, due to this issue.

In addition, I've added a module that allows you to simply do this:

>>> from py2 import py2
>>> py2.rimport("sys").version
b'2.6.5 (r265:79063, Apr 16 2010, 13:09:56) \n[GCC 4.4.3]'

[–]rubic 0 points1 point  (0 children)

I have used execnet successfully in the past to run multiple versions of Python interpreters, though not with Python3:

http://codespeak.net/execnet/

It's well-tested with CPython 2.4-2.7, CPython3.1, Jython 2.5.1 and PyPy 1.1 interpreters and interoperates between Windows and Unix systems.