unable to print Unicode characters in Python 3

Thorsten Kampe thorsten at thorstenkampe.de
Tue Jan 27 13:08:20 EST 2009


* 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:
> > I have this same issue on Windows.
> > Note that on Python 2.6 it works:
> >
> > Python 2.6.1 (r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit
> > (Intel)] on
> > win32
> > Type "help", "copyright", "credits" or "license" for more information.
> >>>> 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.
 
> on 2.6? Without the 'u' prefix, 2.6 will just encode it as a normal
> (byte) string and escape the backslash.

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.

Thorsten



More information about the Python-list mailing list