在 Python 中,如何将编码指定为 fileinput.input ?
我写了
f = fileinput.input(openhook=fileinput.hook_encoded("windows-1252"))
但它不能可靠地工作。 script.py text.txt
得到不同的结果和 script.py < text.txt
最佳答案
这是 fileinput 模块中的一个错误,它只在从文件读取时使用编码信息,而不是从标准输入读取时:(
关于python - 如何为文件输入指定编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13055596/