Convert Python2 code to Python3 with one line of code

Ankur Shrivastava
May 8, 2019 · 2 min read
Related image

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.

In order to convert Python 2.7 code to Python 3, open the directory in Terminal

Command is as follows:

2to3 [file or folder] -w

First of all, install 2to3:

For all files in the current folder and files in the subfolders:

For a particular file in the current folder:

Written by

Marketing Analyst / SEO at ShareChat | Full Stack Digital Marketer

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade