What do you mean you can’t choose between Python 2 and 3?

Should I use Python 2 or 3?

This question gets asked almost every week in some beginners forum. And nobody answers it, as the debates have gotten boring.

It is one of the question’s that is tearing the Python community. The two sides discuss everything in a very civil and reasonable manner (just kidding). The two most common comments are:

Python 3 users: Whaddya mean you’re still using Py 2? Do you also ride horse buggies and send telegraph messages? Come out of your caves and join the 21st century.

Python 2 users: You Py 3 guys live in your ivory tower, drink your fine wine while wearing monocles and saying “Tally Ho, Ole Chap.” What do you know about the problems those of us in the Real World™ face?

And for those of us who just want to get work done (the Git-it-Done folks), all this is a distraction.

Old Man’s advice

At the risk of sounding like a wheezy old cowboy, let me say:

You don’t know where you’re going till you know where you are.

I know it’s cheesy, but the answer maybe easy or hard based on where you are:

1. Complete Beginner

Don’t worry about which version to install. Instead, find a good tutorial. Different people have different preferences. Some people love Learn Python the hard way, others hate it. Some love video courses, some love physical books.

So choose something and you like, and install the Python they recommend. After that, spend five minutes reading the differences between 2 and 3. That way, you can move between them easily.

2. Corporate job

You can’t really choose, can you? You are probably using Windows XP or Debian 5, and you are stuck with whatever version of Python you installed in 1996.

Sure, you could ask your boss to move up the latest version. At the same time, ask them to start naming all projects after Cowboy Bebop characters. Both have an equal chance of success.

3. Personal projects

I mean projects you created to solve a personal itch (though they might become big in the future, you don’t create them for other people to start with).

Like (1), choose what you are comfortable with. If you can, use Python 3, just because it’s an actively developed language.

4. Writing libraries

Wait Armin Ronacher, is that you? You know you have to support both Python 2 and 3, right? Get back to work.

5. Projects you want to share with other people

This is the only category that has some uncertainty. If you are developing a project that you mainly aim to share with others, you can’t assume what version they’ll be using. They might be in a corporate environment and can only run 2.x. Or they might be cutting edge, running the latest 3.x version.

This is different from personal projects, as your main goal (like library writers) is to reach as many people as possible. I faced the same problem when thinking about which Python version to use for my book. This is what I have decided: Use both 2 and 3:

1. Write future proof Python 2.7 code.

2. Convert the code to 3.

This involves extra work, which is why it isn’t suitable for every project.

What if I am stuck with Python 2?

You might be forced to stick with Python 2, especially if you have legacy code.

If you must use 2, then do so. But make sure you use at least Python 2.7, and write future proof code. As far as possible, bring in Python 3s features using from future import  keyword.

Leave a Reply

Your email address will not be published. Required fields are marked *