我正在尝试使用 python 将 UCS-2 Little Endian 文件编码为 utf8,但我遇到了一个奇怪的错误。
我使用的代码:
file=open("C:/AAS01.txt", 'r', encoding='utf8')
lines = file.readlines()
file.close()
我收到以下错误:
Traceback (most recent call last):
File "C:/Users/PycharmProjects/test.py", line 18, in <module>
main()
File "C:/Users/PycharmProjects/test.py", line 7, in main
lines = file.readlines()
File "C:\Python34\lib\codecs.py", line 319, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
我尝试使用编解码器命令,但也没有用... 知道我能做什么吗?
最佳答案
open
的encoding
参数设置encoding='utf s16_le'
。
关于python - 使用python错误将 'UCS-2 Little Endian'文件编码为 'utf8',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45393818/