Future-Proof Your Code: Converting from Python 2 to Python 3 Made Simple

Madhu Sri Sushmitha Chowdary
2 min readJun 30, 2023

--

Python 2 was published in 2000, signalling a more transparent and inclusive language development process. It included many more programmatic features and added more features throughout its development.

Python 2.7 was published in 2010 as the last of the 2.x releases. The intention behind Python 2.7 was to make it easier for Python 2.x users to port features over to Python 3 by providing some measure of compatibility between the two.

Python 3 is regarded as the future of Python and is the version of the language that is currently in development. Released in late 2008, Python 3 addressed and amended intrinsic design flaws. However, Python 3 adoption has been slow due to the language not being backwards compatible with Python 2.

Python 2 to Python 3 Made Simple

Here are the few ways to covert your code repository to the Python3 —

Step 1 : Instal 2to3 library

pip install 2to3

Step 2 : Now use the below syntax to convert a file or a complete folder.

#Basic Syntax
2to3 [file or folder] -w

To Convert Single File

#Command for single file convertion
2to3 medium.py -w

To Convert Complete Folder

#For converting all files in that folder 
2to3 . -w

Now, We are done with converting the files but now we need to check the Library dependencies to run the case successfully. Many popular libraries have already been updated to support Python 3, but some might still be Python 2-only. Make sure to update or find alternative libraries for any incompatible ones.

Follow for more Trending Tech Articles! https://medium.com/@nekkantimadhusri

--

--