WTF? Printing unicode strings
Ron Garret
rNOSPAMon at flownet.com
Thu May 18 18:04:08 EDT 2006
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.
> B) Don't do that.
OK. What should I do instead?
> 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:
>>> import sys
>>> sys.stdout.encoding='utf-8'
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: readonly attribute
>>>
rg
More information about the Python-list
mailing list