Python 2.7 will retire soon

If you are using Python 2.7, you should be start thinking of migrating your script to Python 3.x. As you can see from this website, Python 2.7 will retire in about a year (as of the time this was posted).

Below is the excerpt from the website:

What's all this, then?
Python 2.7 will not be maintained past 2020. Originally, there was no official date. Recently, that date has been updated to January 1, 2020. This clock has been updated accordingly. My original idea was to throw a Python 2 Celebration of Life party at PyCon 2020, to celebrate everything Python 2 did for us. That idea still stands. (If this sounds interesting to you, email pythonclockorg@gmail.com).
Python 2, thank you for your years of faithful service.
Python 3, your time is now.
How do I get started?
If the code you care about is still on Python 2, that's totally understandable. Most of PyPI's popular packages now work on Python 2 and 3, and more are being added every day. Additionally, a number of critical Python projects have pledged to stop supporting Python 2 soon. To ease the transition, the official porting guide has advice for running Python 2 code in Python 3.

How to migrate your Python 2 code to Python 3

If you have Python installed on your system, you should have a tool called “2to3”.

To Check your Python 2 code compatibility with Python 3, run the “2to3”.

Let’s say you have a Python file called “hello_world_py2.py“. And let’s say it has the following code:

print "hello world - Python 2.7"

Next, run the “2to3” tool from the command line like below:

2to3 helloworld_py2.py

And then, you will get an output something like below:

RefactoringTool: Skipping optional fixer: buffer
RefactoringTool: Skipping optional fixer: idioms
RefactoringTool: Skipping optional fixer: set_literal
RefactoringTool: Skipping optional fixer: ws_comma
RefactoringTool: Refactored hello_world_py2.py
--- hello_world_py2.py	(original)
+++ hello_world_py2.py	(refactored)
@@ -1,2 +1,2 @@
-print "hello world - Python 2.7"
+print("hello world - Python 2.7")
 
RefactoringTool: Files that need to be modified:
RefactoringTool: hello_world_py2.py

For more details about “2to3” tool, please check out this page.

If you are thinking of starting to learn Python, I would encourage you to use Python 3.x. already.

Feel free to share this post!

Scroll to Top