【发布时间】:2018-07-11 10:28:52
【问题描述】:
我试图读取 utf-16 文件。这段代码在本地机器上运行良好,但是当我在 AWS Batch 服务上运行它时,它给出了上述错误。
import codecs
file_to_split = codecs.open("file_utf_16.txt", 'r+', "UTF-16")
抛出异常header 'ascii' codec can't encode character '\ufeff' in position 0: ordinal not in range(128)
我正在使用 Python 3.6。
【问题讨论】:
-
文件需要解码
utf-16le而不是utf-16 -
谢谢,但没用。
标签: python python-3.x codec