python3与python2的还是有诸多的不同,比如说在2中:
print "Hello,World!" raw_input()
print ("Hello,World!") input()
# python 2.7.6 # 2to3Test.py print "Hello,World!"
D:\Python>python27 2to3Test.py Hello,World!
D:\Python>python33 2to3Test.py File "2to3Test.py", line 1 print "Hello,World!" ^ SyntaxError: invalid syntax
D:\Python>python C:\Python33\Tools\Scripts\2to3.py -w 2to3Test.py RefactoringTool: Skipping implicit fixer: buffer RefactoringTool: Skipping implicit fixer: idioms RefactoringTool: Skipping implicit fixer: set_literal RefactoringTool: Skipping implicit fixer: ws_comma RefactoringTool: Refactored 2to3Test.py --- 2to3Test.py (original) +++ 2to3Test.py (refactored) @@ -1 +1 @@ -print "Hello,World!" +print("Hello,World!") RefactoringTool: Files that were modified: RefactoringTool: 2to3Test.py
D:\Python>python33 2to3Test.py Hello,World!
总结:
1. 目录. C:\Python33\Tools\Scripts\2to3.py. 其实在python2.6,2.7中都存在这个工具。
2. 如果不加-w参数,则默认只是把转换过程所对应的diff内容打印输出到当前窗口而已。
3. 加了-w,就是把改动内容,写回到原先的文件了。
4. 不想要生成bak文件,再加上-n即可。 bak最好还是有。