gpt4 book ai didi

python - 如何为文件输入指定编码

转载 作者:太空狗 更新时间:2023-10-30 01:09:29 24 4
gpt4 key购买 nike

在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com