简体   繁体   English

python 2to3手动修改

[英]python 2to3 manual modification

Is there a way to change python2.x source code to python 3.x manually. 有没有办法手动将python2.x源代码更改为python 3.x. I guess using lib2to3 this can be done but I don't know exactly how to do this ? 我想使用lib2to3这可以做到但我不确切知道如何做到这一点?

Yes, porting is what you are looking here. 是的,移植就是你在这里看到的。

Porting is a non-trivial task that requires making various decisions about your code. 移植是一项非常重要的任务,需要对您的代码做出各种决定。 For instance, whether or not you want to maintaing backward compatibility. 例如,您是否要维护向后兼容性。 There is no single, universal solution to porting. 移植没有单一的通用解决方案。 The way you port depends on your specific requirements. 您的端口方式取决于您的具体要求。

The best resource I have found for porting apps from Python 2 to 3 is the wiki page PortingPythonToPy3k . 我发现将Python 2中的应用程序移植到3的最佳资源是维基页面PortingPythonToPy3k The page contains several approaches to porting as well as a lot of links to resources that are potentially helpful in porting work. 该页面包含几种移植方法以及许多可能有助于移植工作的资源链接。

Thanks. 谢谢。 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM