Notepad/enter/Coding Tips (Classical)/Terminal Tips/2. CLI Tools/Languages/Python/Convert Python 2 to 3.md

401 B

Use the script 2to3 to upgrade python 2 code to python 3:

This can be done via the command line:

2to3 example.py

To write to the file directly:

2to3 -w example.py

To translate an entire project from one directory tree to another use:

2to3 --output-dir=python3-version/mycode -W -n python2-version/mycode