unable to print Unicode characters in Python 3

Denis Kasak denis.kasak at gmail.com
Tue Jan 27 19:35:49 CET 2009


On Tue, Jan 27, 2009 at 7:08 PM, Thorsten Kampe
<thorsten at thorstenkampe.de> wrote:
> * Denis Kasak (Tue, 27 Jan 2009 14:22:32 +0100)
>> On Tue, Jan 27, 2009 at 1:52 PM, Giampaolo Rodola' <gnewsg at gmail.com>
>> wrote:

<snip>

>> >>>> print unicode('\u20ac')
>> > \u20ac
>>
>> Shouldn't this be
>>
>> print unicode(u'\u20ac')
>
> You are trying to create a Unicode object from a Unicode object. Doesn't
> make any sense.

Of course it doesn't. :-)

Giampaolo's example was wrong because he was creating a str object
with a non-escaped backslash inside it (which automatically got
escaped) and then converting it to a unicode object. In other words,
he was doing:

print unicode('\\u20ac')

so the Unicode escape sequence didn't get interpreted the way he
intended it to. I then modified that by adding the extra 'u' but
forgot to delete the extraneous unicode().

> You are confusing encoding and decoding. unicode(str) = str.decode. To
> print it you have to encode it again to a character set that the
> terminal understands and that contains the desired character.

I agree (except for the first sentence :-) ). As I said, I simply
forgot to delete the call to the unicode builtin.

-- 
Denis Kasak



More information about the Python-list mailing list