ordinal not in range(128)

Fredrik Lundh fredrik at pythonware.com
Sat May 12 09:51:13 EDT 2001

Ralf Claus wrote:
> I could answer the question. But  i do not point why it functioned.
> Normally, this is the way to capture text from a TextWidget.
> (I type äöüäöü in the TextWidget)
> text = self.c.get(1.0,END)
> print text

if the widget contains non-ascii characters, this might result
a unicode string (use repr(text) or type(text) to verify this)

to print a non-ascii unicode string on an output device, you
need to specify the output encoding, e.g:

    print text.encode("iso-8859-1")
    print text.encode("ascii", "ignore")
    print text.encode("utf-8")

(for some reason, typing latin-1 text into a text widget doesn't
always result in a unicode string.  looks like a bug to me...)

Cheers /F

More information about the Python-list mailing list