I have a huge code base which supports Python 2.7.

Now I search a tool which helps me to transform the source code to source code which works on Python 2.7 and Python 3.


Python comes with a tool called 2to3, which is specifically designed for converting Python 2 to Python 3.

Usually, most of the the converted code works in Python 2.7 as well, in particular after imports from __future__. In this case, most of the incompatabilities can be handled on a per-case basis. In my experience, a main exception from this is Unicode string handling, but if you are dealing with that, you want to get completely rid of Python 2 as quickly as possible anyway.

  • The result should be code which runs on both: Python2.7 and Python3. – guettli Feb 5 '18 at 11:56

The futurize script passes Python 2 code through all the appropriate fixers to turn it into valid Python 3 code, and then adds __future__ and future package imports to re-enable compatibility with Python2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.