WTF? Printing unicode strings
Laurent Pointal
laurent.pointal at limsi.fr
Fri May 19 08:13:29 EDT 2006
Ron Garret a écrit :
> In article <mailman.5904.1147987926.27775.python-list at python.org>,
> Fredrik Lundh <fredrik at pythonware.com> wrote:
>
>> Ron Garret wrote:
>>
>>>>>> u'\xbd'
>>> u'\xbd'
>>>>>> print _
>>> Traceback (most recent call last):
>>> File "<stdin>", line 1, in ?
>>> UnicodeEncodeError: 'ascii' codec can't encode character u'\xbd' in
>>> position 0: ordinal not in range(128)
>> so stdout on your machine is ascii, and you don't understand why you
>> cannot print a non-ascii unicode character to it? wtf?
>>
>> </F>
>
> I forgot to mention:
>
>>>> sys.getdefaultencoding()
> 'utf-8'
>>>> print u'\xbd'
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xbd' in
> position 0: ordinal not in range(128)
This is default encoding for evaluation of expressions in u"..."
strings, this has nothing to do with printing.
For the output encoding, see sys.stdout.encoding.
>>> import sys
>>> sys.stdout.encoding
'cp850'
>>>
A+
Laurent.
More information about the Python-list
mailing list