Old Python2 Code Causing you a Headache? Convert Python3 Automagically!

Do you have some Python 2 code hanging around?  Found some example code for exactly what you’re trying to do, but it is written in Python2?  Python 2 has been sunset for a while now.  But converting your Python2 to Python3 can be a pain.  Well, did you know there’s a handy little tool included with most, if not all, Python3 distributions?  I’m using the Anaconda distro, and this tool is super helpful.  

2to3 <filename.py> – this will output a diff of the current Python2 code with changes that should/could be made, but it doesn’t modify the file.  

2to3 -w <filename.py> – this will actually modify filename.py based on the recommendations of the updater.  A backup of the original file will be made, so don’t fret.  

Need more info?  Check out the 2to3 documentation in the Python Docs.  

Happy Coding!