Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.chainon-marquant.org!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'wrote:': 0.16; '>>>': 0.18; 'convert': 0.19; 'from:addr:web.de': 0.23; "skip:' 30": 0.28; 'unicode': 0.28; "skip:' 10": 0.29; 'print': 0.29; 'skip:b 20': 0.29; 'implicitly': 0.30; 'subject:?': 0.30; 'skip:b 30': 0.30; 'to:addr:python-list': 0.33; 'header:X-Complaints-To:1': 0.34; 'received:org': 0.37; 'subject:how': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.40 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: how to get my character? Date: Thu, 26 Jan 2012 14:05:30 +0100 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Gmane-NNTP-Posting-Host: p5084a503.dip.t-dialin.net X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 13 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1327583141 news.xs4all.nl 6928 [2001:888:2000:d::a6]:56461 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19484 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.