如何在python中将Shift_JIS字符代码转换为unicode字符?

时间:2011-08-18 19:44:59

标签: python encoding character shift-jis

我有一个Shift_JIS字符代码列表(整数),我希望将其转换为unicode字符。我想我需要一个适用于其他编码的chr()/unichr()函数版本。 我已将decode()hex()结合使用,但它只解码字符串本身,而不是十六进制值。

输入和输出示例:

input = [91, 92, 48, 528]

output = ["[", "¥", "0", "0"]

任何人都可以帮助我吗?提前谢谢。

1 个答案:

答案 0 :(得分:0)

如果你从这样的事情开始:

bytearray = [65, 66, 67, 200, 156, 130]

然后就可以了:

>>> ustring = reduce(operator.add, map(chr, bytearray)).decode('shift_jis')
>>> ustring
u'ABC\uff88\u6029'
相关问题