5
在Python中,我如何指定編碼爲fileinput.input?如何指定編碼到文件輸入
我寫
f = fileinput.input(openhook=fileinput.hook_encoded("windows-1252"))
但並不可靠地工作。我得到不同的結果script.py text.txt
和script.py < text.txt
在Python中,我如何指定編碼爲fileinput.input?如何指定編碼到文件輸入
我寫
f = fileinput.input(openhook=fileinput.hook_encoded("windows-1252"))
但並不可靠地工作。我得到不同的結果script.py text.txt
和script.py < text.txt
這是的FileInput模塊中的錯誤,它從文件中讀取數據時,不從標準輸入:(閱讀時只使用了編碼信息
的錯誤似乎已在Python 3中修復。 –