Totally confused by Python's string thing.
Jarek Zgoda
jzgoda at usun.gazeta.pl
Tue Dec 17 13:50:44 EST 2002
Dnia Mon, 16 Dec 2002 19:38:11 GMT
"Fredrik Lundh" <fredrik at pythonware.com> pisze:
> > 2) How do I set up my system to deal correctly and robustly with the
> > ISO 8859-1 character set? How about the ISO 8859-2 character set?
>
> convert all text to Unicode strings on the way in, and to the
> appropriate encoding on the way out.
>
> to convert from encoded data to Unicode text, use:
>
> txt = raw.decode(encoding)
>
> or
>
> txt = unicode(raw, encoding)
>
> to convert from Unicode text to encoded data, use:
>
> raw = txt.encode(encoding)
>
> (where "raw" is an encoded string, and "txt" is a unicode string)
I have problems with character encodings in Tkinter. My machine is
Latin2 based (ISO8859-2). If I try to get the value of Entry widget (and
the value contains slavic characters) I always receive an error message:
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.2/lib-tk/Tkinter.py", line 1300, in __call__
return apply(self.func, args)
File "tkentry.py", line 21, in say_hi
print self.entry.get().encode('iso8859_2')
File "/usr/lib/python2.2/encodings/iso8859_2.py", line 18, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeError: charmap encoding error: character maps to <undefined>
It looks like the value of Entry widget is Unicode object. What can I do
to make it work? I have set encoding (following default for my locale,
which is pl_PL) in sitecustomize.py, sys.getdefaultlocale[1] returns
"ISO8859-2". Do I have problem with my Python installation (2.2.2,
compiled from sources), or maybe the problem is somewhere else?
--
Jarek Zgoda
http://www.zgoda.biz/
--
Serwis Usenet w portalu Gazeta.pl -> http://www.gazeta.pl/usenet/
More information about the Python-list
mailing list