A couple of months ago I decided to switch to Python 3.1 for all my spare time projects. Previously I’d been using the Python which is shipped by default on my Mac, 2.6.1. I’m always keen to keep up with new things, and it seemed like maybe enough libraries had been ported to Python 3 to make shifting over easy.
The bytes/str change is the biggest win. In Python 3, a ‘str’ is a string; it’s text in some defined encoding. If you want to have binary data, you can – that’s ‘bytes’. You can go back and forth between the two, but you must provide an encoding when you do so. This is a huge win, as a ‘str’ is always safe to print. It can’t contain binary that isn’t valid according to your string encoding. A string with an umlaut in it is no longer going to unexpectedly break your code.
The removal of ‘lambda’ is a pain. Yes, we’ve got list comprehensions and generator expressions to do one liners, but I still liked ‘lambda’. Without it I find myself declaring a lot of small functions and then calling them just below their definition, which is less readable. [ Edited; it turns out (see comments) that this paragraph is completely wrong ]
Training my brain that print is a function not a statement has been surprisingly hard.
A real problem has been the lack of third party library support for Python 3. It’s nowhere near as far along as I’d thought. I’ve ended up porting Python bindings for things like CouchDB and Twitter to Python 3, but then I’m left with my own fork to maintain. Most of the work of the port is down with the impressive ‘2to3’ tool, but typically there’s some ‘str’ vs ‘bytes’ bits to fix up. Not very fun, and tedious as to try out a new third party library I have to do a bunch of work.
This last problem leads to my biggest problem; sharing my Python 3 programs with other people sucks. I’ve written a little command line twitter client, and to use it a person has to go download a couple of branches of third party libraries I’ve forked to add Python 3 support. A huge pain for that person, and a pain for me as I end up with no users and thus no contributors.
I’m thinking of going back to Python 2, or even shifting off Python to another more exciting language. Any comments from people?