作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
在 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/
我是一名优秀的程序员,十分优秀!