开发者

python unicode support

开发者 https://www.devze.com 2023-01-28 22:44 出处:网络
I\'m trying to figure out how to use the unicode support in python; I would like to convert this string to unicode :

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

精彩评论

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