作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我似乎无法使用内置的 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/
我是一名优秀的程序员,十分优秀!