Skip to content

How to stop worrying and love Python 3

December 6, 2008

There is loads of discussion about Python 3 right now, with people lovin‘ and people hatin‘. Mostly lovin‘ it has to be said. And just to clear some things up right now:

Firstly, unless you are the maintainer of a python library, there is no, I repeat no, reason for you to port to Python 3 right now except that you probably will like it better. That’s it. Python 3 is a amazing language, but Python 2 is still great! If you are happy with Python 2, you can ignore Python 3 and continue as normal. It will take some time before even most Linux distros come with Python 3, dot-zero releases always have bugs, etc, etc. There will come a time where there are more reasons. I’d expect that in a year or so we’ll start getting Python 3 only libraries and stuff. But right now, there is no reason.

Secondly, porting to Python 3 is not so painful as you might be led to believe som from the discussion. 2to3 works fine. I did some testing by runnig a highly complex and magical piece of software through 2to3 in august, namely setuptools. Sure, it didn’t work straight out of the box, but I did get it working. The big problem was that setuptools mixes binary and string data in it’s filehandling. It opens files without either a text or a binary flag, because in python 2.x that flag doens’t actually do anything, and then looks to see if it’s binary or string data by looking at the start of the file. That part needs to be rewritten. I got it, and buildout, running it’s tests and seemingly working with a couple of hours of quick and dirty fixes. Other than that, it worked. 99% of Python software will require that level or lower of TLC after conversion, and converting to Python 3 will for a software project of typical sizes be about a days work, I guess. And the people that needs to port early is going to write documentation for you to help you. So don’t worry. The problem is if you need to support Python 2.5 and Python 3 from the same codebase, because then you will want to modify your 2.5 code so that the 2to3 conversion works without you needing to make any changes to the code afterwards. That’s a bit more work.

Thirdly, it’s perfectly possible to write code that works under both 2.6 and 3.0 without conversion. Yes, I know the whatsnew document doesn’t recommend that, but that document is seriously outdated, and for example claims that you can’t use print. This is incorrect, there if since a long time ago a future import that deals with that in 2.6. And before you need to port to 3.0 there will probably be a 2.7 out, with even more forward compatibility. Most software projects out there doesn’t need to support more than one Python version at a time. Those who do, that is libraries and framework plugins, can for the most part move to 3.0 gradually and support two Python versions at the same time.

So, the conclusion is, Python 3 is not scary, it’s not so incompatible as you think, and I do not think it’s going to split the community. That was a serious worry two years ago, but those who raised that worry, like me and Martijn Faassen, was listened to, and 2.6 has serious amounts of backwards compatibility. So take it easy, it’s going to be fine!

  1. “its perfectly possible to write code that works under both” is an important statement, one which I wish was not downplayed on the site since so many seem to be citing “its not recommended” in their justifications to do nothing.

    I guess its a fine line.

    Here’s one team’s experience with doing just that though:

    The latest release of QP and friends supports Python >= 2.4 and yes, that includes Python 3.0.

    • Yeah, why put all that forwards compatibility into Python 2.6 if you at the same time scream “don’t do it!” πŸ™‚

      I saw your blog about support 2.4 – 3.0, which is cool, I hope to get time to download and look at it.

  2. Dayo permalink

    Which would you recommend a newbie learned? 2.6 or 3.0?

  3. Hey guys. I am 12 years old and I have had experience with BASIC. I am thinking about learning Python, but I’m not sure if I should learn the 2.6 version or the 3rd version. I don’t really care about libraries or anything quite yet. I was wondering if it is easier to code in 3.0 than 2.6. And is it more fun and productive?

    I would also appreciate it if you could point me in the right direction for a complete tutorial that is easy to understand and teaches Object Oriented Programing. I don’t really care if it doesn’t teach OOP.


  4. commander thor permalink

    Hey MR-J, learn 2.6 I learnt it in December, and I’m already using it for my little scripts for lab in school, and i plan to stick to python for a long time to come! I tried 3.0, but once you’ve learnt to use the language (takes 3 days), there is no productivity from you. because you need the libraries and tutorials, all of which are still written for 2.6…hope this helps πŸ™‚

  5. Renren permalink

    Learn 2.x and then 3.x, just so you know the difference.

    By the time you need to do some serious programming, there will be enough 3.x libraries.

    A good book to start would be “Think Python”

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: