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 14:19 UTC (Thu) by bartoldeman (guest, #4205)
In reply to: Python moratorium and the future of 2.x by michaeljt
Parent article: Python moratorium and the future of 2.x

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.


(Log in to post comments)


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