python自带的语言版本转换工具2to3.py使用起来很简单。
(1)使用Windows 命令提示符(cmd)打开2to3.py 脚本所在位置,如下图:
按指定代码转换
(2)在cmd的控制台环境下,先定位到你的2to3.py文件所在的路径,比如D:\Anaconda3\Tools\scripts
包含了这个文件。然后输入命令:
D:\Anaconda3\Tools\scripts>python 2to3.py -w G:\Google下载\machinelearninginaction\Ch06\svmMLiA.py
G:\Google下载\machinelearninginaction\Ch06\svmMLiA.py
文件为你要转换的文件的路径和名称
转换信息如下:把每一个需要转换的代码都进行转换。(中间转换的信息省略)
RefactoringTool: Skipping optional fixer: buffer
RefactoringTool: Skipping optional fixer: idioms
RefactoringTool: Skipping optional fixer: set_literal
RefactoringTool: Skipping optional fixer: ws_comma
RefactoringTool: Refactored G:\Google下载\machinelearninginaction\Ch06\svmMLiA.py
--- G:\Google下载\machinelearninginaction\Ch06\svmMLiA.py (original)
+++ G:\Google下载\machinelearninginaction\Ch06\svmMLiA.py (refactored)
................
................
................
RefactoringTool: Files that were modified:
RefactoringTool: G:\Google下载\machinelearninginaction\Ch06\svmMLiA.py
按目录转换(可以转换目录下的所有代码包括子文件夹下的.py文件)
D:\Anaconda3\Tools\scripts>python 2to3.py -w G:\Google下载\machinelearninginaction\Ch06\EXTRAS
G:\Google下载\machinelearninginaction\Ch06\EXTRAS
文件夹为你要转换的文件夹的路径和名称
转换信息如下:
RefactoringTool: Skipping optional fixer: buffer
RefactoringTool: Skipping optional fixer: idioms
RefactoringTool: Skipping optional fixer: set_literal
RefactoringTool: Skipping optional fixer: ws_comma
RefactoringTool: Refactored G:\Google下载\machinelearninginaction\Ch06\EXTRAS\notLinSeperable.py
--- G:\Google下载\machinelearninginaction\Ch06\EXTRAS\notLinSeperable.py (original)
+++ G:\Google下载\machinelearninginaction\Ch06\EXTRAS\notLinSeperable.py (refactored)
@@ -65,4 +65,4 @@
ax.scatter(xcord1,ycord1, marker='o', s=50, c='red')
plt.title('D')
plt.show()
-print 'nima'
+print('nima')
RefactoringTool: No changes to G:\Google下载\machinelearninginaction\Ch06\EXTRAS\plotRBF.py
RefactoringTool: No changes to G:\Google下载\machinelearninginaction\Ch06\EXTRAS\plotSupportVectors.py
RefactoringTool: Files that were modified:
RefactoringTool: G:\Google下载\machinelearninginaction\Ch06\EXTRAS\notLinSeperable.py
RefactoringTool: G:\Google下载\machinelearninginaction\Ch06\EXTRAS\plotRBF.py
RefactoringTool: G:\Google下载\machinelearninginaction\Ch06\EXTRAS\plotSupportVectors.py