Python 2to3 manual modification

Is there a way to change the source code of python2.x to python 3.x manually. I guess lib2to3 can do this, but I don’t know exactly how to do this?

+3
source share
2 answers

Thank. Here is the answer I was looking for:

from lib2to3.refactor import RefactoringTool, get_fixers_from_package
"""assume `files` to a be a list of all filenames you want to convert"""
r = RefactoringTool(get_fixers_from_package('lib2to3.fixes'))
r.refactor(files, write=True)
+2
source

Yes, porting is what you are looking for here.

Porting is a non-trivial task that requires various decisions regarding your code. For example, do you want to maintain backward compatibility. There is no one universal solution for porting. The way you port depends on your specific requirements.

, Python 2 3, - wiki PortingPythonToPy3k. , , .

+4

Source: https://habr.com/ru/post/1769893/


All Articles