[Tutor] Using special characters in Python

Scot Stevenson scot@possum.in-berlin.de
Fri Feb 21 11:52:12 2003


Hello Ole,=20

> The problem is that in Danish (and Norwegian) we have some characters i=
n
> the alphabet that doesn not exist in the english one, i.e. =E6, =F8, an=
d =E5 (in
> case you can see them correctly here they are in html: æ and &osl=
ash;
> and å)

I have had the same problem with German Umlauts since I started with Pyth=
on.=20
It is not so much due to Python, which handles non-US-characters beautifu=
lly,=20
but Tkinter, which doesn't, and keeps spitting out things like your=20

> UnicodeError: ASCII encoding error: ordinal not in range(128)

I acutally spent the better part of an evening trying to get Tkinter to a=
ccept=20
Umlauts to use with the email.Utils.unquote() method, up to the point whe=
re I=20
was systematically testing just what encoding Tkinter was returning the=20
string in (UTF-8? UTF-16? ISO-8859-1? 7-bit ASCII? Klingon?) but to no av=
ail.=20
I ended up doing it the hard way with the older quopri module via cString=
IO,=20
which is ugly, but at least works.=20

Anyway, what has worked for me in the past (but for some reason doesn't w=
ork=20
every time) is a line such as:

theinputstring =3D theinputstring.encode("ISO-8859-1")

I'm sure there is some perfectly logical reason why Tkinter doesn't seaml=
essly=20
integrate with Python when you are trying to do something else than Engli=
sh,=20
but if I wanted to do things the hard way, I'd be programming in C++.=20
Switching to Qt is on my to-do list - Tkinter was okay to get started, bu=
t=20
details like this just eat up too much time.=20

Y, Scot

--=20
  Scot W. Stevenson -- scot@possum.in-berlin.de -- Zepernick, Germany