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


Groups > comp.lang.python > #19484 > unrolled thread

Re: how to get my character?

Started byPeter Otten <__peter__@web.de>
First post2012-01-26 14:05 +0100
Last post2012-01-26 14:05 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#19484 — Re: how to get my character?

FromPeter Otten <__peter__@web.de>
Date2012-01-26 14:05 +0100
SubjectRe: how to get my character?
Message-ID<mailman.5121.1327583141.27778.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web