DEV Community

Cover image for My Take on Python Version 2 vs 3
Kajigga for Scripting With Python

Posted on • Originally published at scriptingwithpython.com on

My Take on Python Version 2 vs 3

It's a huge point of conversation.

The internet has been debating the merits of Python 2 vs Python 3 for years now. I am sure the Python foundation would love for everyone to have switched entirely to Python 3 by now. There are reasons to migrate to it and, at least some feel, reasons to stay on 2.7.

I'll summarize the differences then give my own opinionated take on the whole thing. (Hint: I think everyone should be using Python 3)

Python 2.7

Python 2.7.13, the most recent version of the 2.x series, came out way back in 2010.

Problems with Python 2.7

No new features have been introduced since that time. The Foundation releases bug fixes but new functionality will only be added to Python 3.

Python 3.x

Pros

  • Iterators, generators
    • Many lists that would have been in memory lists with 2.7 are generators in Python 3. This make high memory functions much more efficient. There are some disadvantages but I won't go into detail here.
  • True UTF8 support - all strings are utf8 by default (Huge win!)
  • New features will be added to Python 3
  • It is not 7 years since the last release

Cons

  • Some libraries have not yet been migrated over to support Python 3. This is a huge problem for some people that have code written to rely on these libraries. However, it is my opinion that if the library isn't popular enough to demand a Python 3 version then it may not be necessary. That or get with the game people.
    • I should note that it has been years since I ran into a library that I wanted to use that didn't work in Python 3.

My Opinion

Use Python 3 unless you absolutely have to use Python 2 for some reason. Python 3 is faster and better supported. All of the solutions I share on Scripting With Python are written with Python 3 first in mind. I may occasionally test them with Python 2 but I won't guarantee it.

Top comments (5)

Collapse
 
tascamtom profile image
Tom Duffy

RHEL 6 uses python 2.6
Yum (package management) is written in Python. RedHat can not work without that v of Python

RHEL 6 is going EOL 11/30/2020

-> You need a way to run Python 3.x without affecting the system's version.
-> Any Python package you add, you need to be sure it sees the python 3.x version rather than the system version. I ran in to this several times, ended up with Py2.6 compatible packages installed regardless.

Collapse
 
kajigga profile image
Kajigga

This is a good reason to use virtual environments when developing in Python. Along with several other good side effects, a virtual environment ensures that code is executed with the version of python you intend. It also attaches any modules installed with pip to that version of Python.

See scriptingwithpython.com/setting-up... for more info.

Collapse
 
yssybyl profile image
Dr Janet Bastiman

I have a policy in my team that if they find something that isn't compatible with python 3 then they should make it compatible and release it back. For now, this has come up with some creative workarounds as they're a little nervous of community contributions!

Collapse
 
kajigga profile image
Kajigga

I've seen similar things done with my projects as well. There are fewer and fewer good reasons to write Python 3 incompatible code. Most, if not all, of the large popular libraries have support for it.

A huge benefit to your team's approach is that it forces the developers to be aware of python3 incompatibilities and to learn new concepts.

Collapse
 
djumaka profile image
Boyan Djumakov • Edited

Transition in the PHP community from 5 to 7 was made by force... Leading frameworks sat down together and said that they will stop supporting old version in half a year, then it's all on you.