Python 3: reading UCS-2 (BE) file

前端 未结 1 1072
臣服心动
臣服心动 2020-12-06 06:11

I can\'t seem to be able to decode UCS-2 BE files (legacy stuff) under Python 3.3, using the built-in open() function (stack trace shows UnicodeDecodeError and contains my r

相关标签:
1条回答
  • 2020-12-06 06:48

    UCS-2 is UTF-16, really, for any codepoint that was assigned when it was still called UCS-2 in any case.

    Open it with encoding='utf16'. If there is no BOM (the Byte order mark, 2 bytes at the start, for BE that'd be \xfe\xff), then use encoding='utf_16_be' to force a byte order.

    0 讨论(0)
提交回复
热议问题