开发者

python unicode support

I'm trying to figure out how to use the unicode support in python; I would like to convert this string to unicode : "AB开发者_运维百科CDE" --> "\x00A\x00B\x00C\x00D\x00E"

Any built-in functionnality can do that, or shall i use join() ?

Thanks !


That's UTF-16BE, not Unicode.

>>> 'ABCDE'.decode('ascii').encode('utf-16be')
'\x00A\x00B\x00C\x00D\x00E'


The key to understanding unicode in python is that unicode means UNICODE. A unicode object is an idealized representation to the characters, not actual bytes.


the str object should be firstly converted to unicode object by decode method. then convert the unicode object to str object using encode method with character-encoding you want.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜