Unicode, stdout, and stderr

Lele Gaifax lele at metapensiero.it
Tue Jul 22 08:49:13 CEST 2014


"Frank Millman" <frank at chagford.com> writes:

> Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit 
> (In
> tel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>>>> x = '\u2119'
>>>> x  # this uses stderr
> '\u2119'
>>>> print(x)  # this uses stdout
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "C:\Python34\lib\encodings\cp437.py", line 19, in encode
>     return codecs.charmap_encode(input,self.errors,encoding_map)[0]
> UnicodeEncodeError: 'charmap' codec can't encode character '\u2119' in 
> position
> 0: character maps to <undefined>
>>>>

No, both statements actually emit noise on the standard output, but the
former prints the *repr* of the string, the latter tries to encode it to
CP437, which you console seems to be using.

One approach could be changing the "code page" (that is, the encoding)
of the "terminal" (see the "chcp" command), to select one that actually
have that glyph. But I'm really guessing here...

ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele at metapensiero.it  |                 -- Fortunato Depero, 1929.




More information about the Python-list mailing list