pythonpython-2.7python-3.3python-2to3

How to use 2to3 properly for python?


I have some code in python 2.7 and I want to convert it all into python 3.3 code. I know 2to3 can be used but I am not sure exactly how to use it.


Solution

  • Install the following module which adds the 2to3 command directly to entry_points.

    pip install 2to3
    

    As it is written on 2to3 docs, to translate an entire project from one directory tree to another, use:

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