1. python2 程序轉(zhuǎn)換為python3
使用python3自帶的程序2to3。 若是安裝包安裝python3,則2to3在Tools文件夾中,若使用conda安裝python3,則在bin目錄下。
2to3 -w python2/ -n -o python3/
2. python3和python2常見的報(bào)錯(cuò)
TypeError: a bytes-like object is required, not 'str'
python bytes和str兩種類型可以通過函數(shù)encode()和decode()相互轉(zhuǎn)換
str? ? --->>> bytes? ? ? encode()
bytes ---->>>str? ? ? decode()
line.strip().split()? ---->> line.decode().strip().split()