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


Groups > comp.lang.python > #19487

Re: how to get my character?

Date 2012-01-26 08:17 -0500
From Dave Angel <d@davea.name>
Subject Re: how to get my character?
References <CA+YdQ_4WU74F-KhBarmt4hT=rzXoZR6nrrtmP-foyBk6yNQCcA@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.5125.1327583906.27778.python-list@python.org> (permalink)

Show all headers | 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