how to get my character?

Peter Otten __peter__ at web.de
Thu Jan 26 08:05:30 EST 2012


contro opinion wrote:

> how can i get "你好" from '\xc4\xe3\xba\xc3' ?

>>> print '\xc4\xe3\xba\xc3'.decode("gbk")
你好

General rule: use the decode() method to convert from bytestring to unicode 
and encode() to convert from unicode to bytestring.

bytestring.encode(x) will implicitly try 
bytestring.decode("ascii").encode(x) which is likely to fail.




More information about the Python-list mailing list