print() and unicode strings (python 3.1)

7stud bbxx789_05ss at yahoo.com
Mon Aug 24 20:45:17 CEST 2009


On Aug 24, 12:19 pm, Stefan Behnel <stefan... at behnel.de> wrote:
> 7stud wrote:
> > python 3.1 won't let me
> > explicitly encode my unicode string
>
> Sure it does. But encoding a non-ASCII string to ASCII will necessarily fail.
>

As you should be able to see in the python 3.1 example I posted, I did
not encode the string using the ascii codec.  I encoded it with the
utf-8 codec, and unfortunately in python 3.1 that creates a "bytes
string", and print()'ing a bytes string does not produce human
readable text.


> > and python 3.1 implicitly does
> > the encoding with the wrong codec.
>
> That's not a Python problem, though. Your terminal is configured for
> US-ASCII, so you can't output anything but US-ASCII characters.
>

My terminal is configured for utf-8, and from the output of the python
2.6 example I posted, it should be apparent that my terminal is
capable of rendering the euro character.






More information about the Python-list mailing list