WTF? Printing unicode strings
Robert Kern
robert.kern at gmail.com
Thu May 18 18:08:30 EDT 2006
Ron Garret wrote:
> In article <mailman.5906.1147989402.27775.python-list at python.org>,
> Robert Kern <robert.kern at gmail.com> wrote:
>
>>Ron Garret wrote:
>>
>>>I forgot to mention:
>>>
>>>
>>>>>>sys.getdefaultencoding()
>>>
>>>'utf-8'
>>
>>A) You shouldn't be able to do that.
>
> What can I say? I can.
See B).
>>B) Don't do that.
>
> OK. What should I do instead?
See below.
>>C) It's not relevant to the encoding of stdout which determines how unicode
>>strings get converted to bytes when printing them:
>>
>>>>>import sys
>>>>>sys.stdout.encoding
>>
>>'UTF-8'
>>
>>>>>sys.getdefaultencoding()
>>
>>'ascii'
>>
>>>>>print u'\xbd'
>>
>>1⁄2
>
> OK, so how am I supposed to change the encoding of sys.stdout? It comes
> up as US-ASCII on my system. Simply setting it doesn't work:
You will have to use a terminal that accepts UTF-8.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list
mailing list