Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19484

Re: how to get my character?

From Peter Otten <__peter__@web.de>
Subject Re: how to get my character?
Date 2012-01-26 14:05 +0100
Organization None
References <CA+YdQ_4WU74F-KhBarmt4hT=rzXoZR6nrrtmP-foyBk6yNQCcA@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.5121.1327583141.27778.python-list@python.org> (permalink)

Show all headers | View raw


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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: how to get my character? Peter Otten <__peter__@web.de> - 2012-01-26 14:05 +0100

csiph-web