使用2to3在原地编辑文件的方法?

2024-09-29 21:35:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我可以在终端中加载2to3文件。它进行大量打印,输出如下:

- print str
+ print(str)  ... 

但文件没有更改。我在“run2to3”之后没有任何指示。请帮忙。在


Tags: 文件终端printstrrun2to3
1条回答
网友
1楼 · 发布于 2024-09-29 21:35:10

如果您search for “2to3”,第一个结果是documentation for 2to3。如文档所述,要覆盖文件而不是打印diff,只需添加-w标志:

[When you run the following:]

$ 2to3 example.py

A diff against the original source file is printed. 2to3 can also write the needed modifications right back to the source file. (A backup of the original file is made unless -n is also given.) Writing the changes back is enabled with the -w flag:

$ 2to3 -w example.py

相关问题 更多 >

    热门问题