help me get excited about python 3

K Richard Pixley rich at noir.com
Thu Jan 5 16:34:30 EST 2012


You get some of the good stuff by importing future, unicode literals 
which essentially means you're working in unicode by default most of the 
time, and print function, (a small fix but long overdue).

I try to write python3 whenever I can.  It's rare that dependencies keep 
me back.  More often it's debugger problems or lack of distributions, 
(python3 doesn't entirely build on MacOsX Lion and the distributed 
binaries can't download third party code that requires compilation).

If you do anything with raw data, the bytes/unicode upgrades are a god 
send.  The old way was workable, (although I still don't understand 
string quoting).  The new way is much better, more rational, easier to 
understand, more consistent, better documented, closer to intuitive 
expectations, and expressively clearer.  Trying to find idioms that work 
for both is horrendous, though.

Unicode rocks.  This change alone is leading me to use python in many 
places where, in the past, I would have used /bin/sh for portability. 
Utf-8 file names, file names with spaces and other "special characters", 
and user entered data fields with diacriticals are all difficult to 
handle in /bin/sh, awkward in python2, but near trivial in python3.

Classic classes are finally dead.

Range now works like xrange used to.  This is great, although a bit 
clumsy when trying to write for both 2 and 3 concurrently.

In practice, most of the library changes are 1:1 renames, which are both 
worthwhile and easy enough to work with.

Most of the other interesting features, (imo), have been backported to 
2.7.  Context managers, "with", str.format(), etc.

I'm currently writing in both more or less concurrently most of the 
time, (can't afford to live without the debugger), and I'm really, 
REALLY looking forward to the day when I can drop the python2 idioms.  I 
really hate adding crap to python3 clean code in order to backport 
support for python2.

Really, the biggest win to 3, aside from the unicode/bytes change, is 
the fact that a lot of outdated stuff is finally getting flushed.  IMO, 
it's not so much about the new features, (context managers are big, but 
have been backported), as it is about the lack of pollution from ancient 
ones.  Many of the new changes are ramifications of these removals.

--rich



More information about the Python-list mailing list