[Numpy-discussion] Greek Letters

Robert Kern robert.kern@gmail....
Tue Feb 20 19:36:19 CST 2007

Mark Janikas wrote:
> Thanks Robert.... but alas, I get.....
>>>> import sys
>>>> sys.stdout.encoding
> 'cp437'
>>>> print u'\u03a7\u00b2'.encode(sys.stdout.encoding)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "C:\Python24\lib\encodings\cp437.py", line 18, in encode
>     return codecs.charmap_encode(input,errors,encoding_map)
> UnicodeEncodeError: 'charmap' codec can't encode character u'\u03a7' in position
>  0: character maps to <undefined>
> Ill keep at it.... please let me know if you have any solutions....

Yup, CP437 doesn't support the Χ character. You will have to use a terminal that
can accept a full-Unicode encoding like UTF-8 and a font that has the relevant
characters. Most of the modern terminal emulators for Linux et al. are capable
of UTF-8. On Windows, you may be out of luck. I don't know of any
fully-Unicode-capable terminal. Google tells me that cmd.exe takes a /U argument
that should put it in Unicode mode, but that doesn't change anything for me.

I also ran into a case where sys.stdout.encoding is None, so my solution is not
as robust as I thought.

If you use something else for your interpreter shell like IDLE, it is possible
that it supports Unicode. sys.stdout.encoding may not be set appropriately, though.

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 Numpy-discussion mailing list