加载中...
You are here:About>Computing & Technology>Python
About.comPython

Al Lukaszewski's Python Blog

From Al Lukaszewski,
Your Guide to Python.
FREE Newsletter. Sign Up Now!

Update on Python 3000

With Python 2.5 having come out last October and Python 2.6 not yet out of beta, one could wonder why the Python developers are releasing information about Python 3000 now, a full year before its expected release. The reason is simple: it's the end of the (Python) world as we know it. Python 3000 (aka, Python 3.0) is going to break backwards compatability in several ways with the entire 2.x series and will leave 1.x as ancient history. The most important breaks posted thus far include:
  • The print statement has been changed to a print function. Instead of
    print "Hello, World!"
    You will need to write:
    print('Hello, World!')
  • Python 3 uses strings and bytes instead of Unicode strings and 8-bit strings. This is a solution to the 2.x bugs which arise from encoding issues.
  • File I/O will require an encoding. The wrong encoding will likely result in an I/O error.
  • Bytes are not hashable and will lose some functions like lower, strip, and split. For these one should use the string methods.
  • map() and filter() return iterators.
  • dict methods return views instead of lists.
  • Simple division returns a float (e.g., '1/2'). Doubling the division symbol gets the truncated version (e.g., '1//2').
  • Code that unconditionally strips the trailing L from the repr() of a long integer will chop off the last digit instead.
There are several other issues that you should be aware of with regard to how Python 3000 handles strings, bytes, classes, and exceptions. These are posted as part of "What�s New in Python 3.0". Be sure to read it when deciding whether to migrate.

All of these features/issues come with Python 3.0 but not before. Consequently, there is as yet no way for you to buffer your code against incompatabilities by starting to write in 3.0 style now. Expect to review and rewrite as needed. Expect also to have two groups of Python programmers for a few years after the advent of 3.0. Many development groups will probably stay with the 2.x series for the compatability, upgrading to 3.0 only when necessary.
Thursday September 20, 2007 | comments (0)

Email to a Friend

Display Latest Headlines | | | Read Archives

powered by WordPress

 All Topics | Email Article | Print this Page | |
Advertising Info | News & Events | Work at About | SiteMap | Reprints | HelpOur Story | Be a Guide
User Agreement | Ethics Policy | Patent Info. | Privacy Policy©2008 About, Inc., A part of The New York Times Company. All rights reserved.