User: Password:
|
|
Subscribe / Log in / New account

Python moratorium and the future of 2.x

Python moratorium and the future of 2.x

Posted Nov 12, 2009 8:58 UTC (Thu) by michaeljt (subscriber, #39183)
Parent article: Python moratorium and the future of 2.x

Is it not possible to write code that works with both Python 2 and Python 3? If so, perhaps a few "code bash days" in which important existing code was reworked might do a lot for uptake of Python 3.

I do find it rather surprising that people think that the core language can't survive for a couple of years without new features. Libraries are a different matter, but new library features can also be done in external libraries, and brought in after the end of the freeze if that makes sense.


(Log in to post comments)

Python moratorium and the future of 2.x

Posted Nov 12, 2009 14:19 UTC (Thu) by bartoldeman (guest, #4205) [Link]

It's possible to write code that works in both, though it may not be particularly elegant, especially if you use unicode strings. You'd need to use things like
"".encode("ascii").join(slist)
instead of just
"".join(slist)
or
b"".join(slist)
if slist is a list of byte strings. And use
    try:
        f = open(filename,mode)
    except IOError:
        s = sys.exc_info()[1]
instead of
    except IOError, s:
or
    except IOError as s:

Though it also depends on your 2.x baseline; 2.6 already supports a lot of the 3.x syntax. Supporting all the way up from less than 2.2 (not to mention 1.5.2) is going to be much more painful though, as 2.1 supports has_key() but not "in" for dictionaries, and 3.x is the other way around.

See also: here and here.


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds