Akarsh
Akarsh

Reputation: 389

Python project conversion 2.7 to 3.4

I have a python project which is built on 2.7 version. I would like to convert the complete project to be compatible with 3.4 version. Is there a way to convert the entire project at once or should I do it file by file ?

2to3 -w pythonfile.py

Upvotes: 1

Views: 1418

Answers (1)

Jaxian
Jaxian

Reputation: 1146

You should be able to convert the entire project at once. I'd recommend putting all of your python's .py project files in the same directory (even though the 2to3 module is supposed to work recursively through directories).

Usage Instructions can be found here: https://docs.python.org/2/library/2to3.html

Just a few other tips:

Before anything I would save a backup copy of your Python 2 file first.

You can then try to convert the code using the "2to3" Automated Python 2 to 3 code translation tool which is built into Python via the Standard Library. Here is another guide on usage: https://www.youtube.com/watch?v=8qxKYnAsNuU

You also have the choice between two tools to port your code automatically: Modernize and Futurize. Check them out below.

Modernize --> https://python-modernize.readthedocs.io/en/latest/

Futurize --> http://python-future.org/automatic_conversion.html

Good luck!

Upvotes: 1

Related Questions