[Numpy-discussion] Greek Letters

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


Mark Janikas wrote:
> Hello all,
> 
> I was wondering how I could print the chi-squared symbol in python.  I
> have been looking at the Unicode docs, but I figured I would ask for
> assistance here while I delve into it.  Thanks for any help in advance.

Print it where? To the terminal (which one?)? In HTML? With some GUI?

Assuming that you have a Unicode-capable terminal, you can find out the encoding
it uses by looking at sys.stdout.encoding. Encode your Unicode string with that
encoding, and print it. E.g., I use iTerm on OS X and set it to use UTF-8 as the
encoding:

In [5]: import sys

In [6]: sys.stdout.encoding
Out[6]: 'UTF-8'

In [7]: print u'\u03a7\u00b2'.encode(sys.stdout.encoding)
Χ²

-- 
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