the Gravity of Python 2

Martijn Faassen faassen at startifact.com
Tue Jan 7 11:07:10 EST 2014


Hi there,

I just tried this out with the future module to see what it actually 
does, and I got this:

On 01/07/2014 01:54 PM, Martijn Faassen wrote:

> First the Python 3 behavior:
>
> py3str + py3str = py3str

Yup, of course.

> py3bytes + py3bytes = py3bytes

Again of course.

> py3str + py3bytes = error

Yup, that's an error.

> Then the behavior of when Python 3 str/bytes are mixed with Python 2 str
> and unicode:
>
> py3str + py2unicode = py2unicode

This didn't work as I expected; I'd have expected py2unicode for 
compatibility reasons, as py3str cannot be combined with py2str (but in 
fact it *can*, odd).

> py3str + py2str = py2unicode

This in fact returns py3str, which I didn't expect either.

> py3bytes + py2str = py2str

And this gets me py3bytes.

I'll get in touch with the author of the 'future' module to try to 
understand why his reasoning is different from mine, i.e. where I'm wrong.

Regards,

Martijn





More information about the Python-list mailing list