windows系統下的使用方法:
(1)將python安裝包下的Tools/Scripts下面的2to3.py拷貝到需要轉換文件目錄中。
(2)dos切換到需要轉換的文件目錄下,運行命令2to3.py test.py
可打印test.py,在python2與python3的差異。
(3)dos切換到需要轉換的文件目錄下,運行命令2to3.py -w test.py
將test.py備份為test.py.bak文件
test.py將相應的格式及相應包改寫為python3
恭喜你,python2到python3的格式修改成功。
同時,迎接你的可能還是不少異常。例如下面的描述:
現象1:
TypeError: cannot use a string pattern on a bytes-like object
原因:
正則表達式是Unicode字符串,但是urlopen()的 read()是ASCII/bytes 字符串。
The fix here is to compile a bytes object instead of a text string.
即改為
REGIX = compile(b'#([\d,]+)')
----- 未完----
不斷學習中
