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


Groups > comp.lang.python > #19487

Re: how to get my character?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <d@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'encoded': 0.05; 'ascii': 0.07; 'encoding.': 0.09; 'am,': 0.12; 'cc:addr:python-list': 0.15; 'codec': 0.16; 'encode': 0.16; 'encoded.': 0.16; 'ordinal': 0.16; 'received:192.168.1.104': 0.16; 'wrote:': 0.16; 'string,': 0.18; '(most': 0.21; 'header:In-Reply-To:1': 0.22; 'byte': 0.24; 'traceback': 0.24; 'cc:2**0': 0.25; "skip:' 30": 0.28; 'unicode': 0.28; "skip:' 10": 0.29; 'print': 0.29; 'cc:addr:python.org': 0.29; 'subject:?': 0.30; "can't": 0.32; 'header:User-Agent:1': 0.33; 'last):': 0.34; 'try:': 0.34; 'something': 0.35; 'file': 0.35; 'two': 0.37; 'but': 0.37; 'could': 0.37; 'received:192': 0.38; 'should': 0.38; 'subject:how': 0.39; 'sense': 0.39; 'received:192.168.1': 0.39; 'subject:: ': 0.39; 'your': 0.61; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.72; 'charset:gb2312': 0.78
Date Thu, 26 Jan 2012 08:17:49 -0500
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111109 Thunderbird/3.1.16
MIME-Version 1.0
To contro opinion <contropinion@gmail.com>
Subject Re: how to get my character?
References <CA+YdQ_4WU74F-KhBarmt4hT=rzXoZR6nrrtmP-foyBk6yNQCcA@mail.gmail.com>
In-Reply-To <CA+YdQ_4WU74F-KhBarmt4hT=rzXoZR6nrrtmP-foyBk6yNQCcA@mail.gmail.com>
Content-Type text/plain; charset=GB2312
Content-Transfer-Encoding 8bit
X-Provags-ID V02:K0:n7WPPJ4rErvk+poVf97VUIJK/fG1zCUrLBtQALhiuNE EPO0QiyBfnYT/L6EXQHKopdyBZBlg8WVHKKKDbI7Qy1FX5fNfx ROkV4C/H7EcBgqHYoqhhhwk38fZai/a67bCJeVmAjSK4iRxupr yOVIUsH0afUW/meU1f2I+XQWcV6cZCBkqQ/yfLqatChp1G5pzD fW/zKRw4/39jKbY6jcg38i3hb9wCgfSIS1QvCJjGsr6LtqcHkY rQW6f+Vwsi8kmFBHMxXKipJ75ZR0PTWXM3883j5t3JrVhN6xFq /Taa+f0Z71rpSMNbMsYvhwdwpY5F4WfGwKAnnKy0HTI1+2vqA= =
Cc python-list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To d@davea.name
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5125.1327583906.27778.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1327583906 news.xs4all.nl 6963 [2001:888:2000:d::a6]:52945
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:19487

Show key headers only | View raw


On 01/26/2012 07:52 AM, contro opinion wrote:
> my system:xp+python27 the codec, xp gbk;python 27 ascii
>
>  a = '你好'
> a
> '\xc4\xe3\xba\xc3'
> print a
> 你好
> '\xc4\xe3\xba\xc3'.decode('gbk')
> u'\u4f60\u597d'
> '\xc4\xe3\xba\xc3'.encode('gbk')
> Traceback (most recent call last): File "", line 1, in UnicodeDecodeError:
> 'ascii' codec can't decode byte 0xc4 in position 0: ordinal not in
> range(128)
>
>  how can i get "你好" from '\xc4\xe3\xba\xc3' ?
>
I don't have 'gbk' as my encoding. But on your system, if you simply
print it, you should get the proper characters.

Try:
a = '\xc4\xe3\xba\xc3'
print repr(a)
print a

And see if it now make sense. You're looking at the encoded form of the
two characters. You could decode it to the two-character unicode string,
as you showed above. But it makes no sense to try to encode something
that's already encoded.

-- 

DaveA

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


Thread

Re: how to get my character? Dave Angel <d@davea.name> - 2012-01-26 08:17 -0500

csiph-web