开发者

How can I convert Shift_JIS character codes to unicode characters in python?

I have a list of Shift_JIS character codes (in integers) that I want to convert into unicode charact开发者_JAVA技巧ers. I think I need a version of the chr()/unichr() function that works in other encodings. I've tried decode() in combination with hex(), but it only decodes the string itself, not the hexadecimal value.

Example input and output:

input = [91, 92, 48, 528]

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

Can anyone help me? Thanks in advance.


If you start with something like this:

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

Then this would do it:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜