gpt4 book ai didi

file - python 3 : reading UCS-2 (BE) file

转载 作者:行者123 更新时间:2023-12-04 09:11:17 24 4
gpt4 key购买 nike

我似乎无法使用内置的 open() 函数在 Python 3.3 下解码 UCS-2 BE 文件(遗留文件)(堆栈跟踪显示 UnicodeDecodeError 并包含我的 readLine() 方法) - 事实上,我无法找到用于指定此编码的标志。

使用 Windows 8,终端设置为代码页 65001,使用“Lucida Console”字体。

代码片段不会有太大帮助,我想:

def display_resource():
f = open(r'D:\workspace\resources\JP.res', encoding=<??tried_several??>)
while True:
line = f.readline()
if len(line) == 0:
break

感谢对这个问题的任何见解。

最佳答案

UCS-2 is UTF-16 ,实际上,对于在任何情况下仍称为 UCS-2 时分配的任何代码点。

encoding='utf16' 打开它.如果没有 BOM( Byte order mark ,开头的 2 个字节,对于 BE 那将是 \xfe\xff ),然后使用 encoding='utf_16_be'强制字节顺序。

关于file - python 3 : reading UCS-2 (BE) file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14488346/

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