[Tutor] Using special characters in Python

Ole Jensen learning.python@dbmail.dk
Fri Feb 21 14:13:01 2003


Olé
ole_jensen@dbmail.dk
----- Original Message -----
From: "Scot Stevenson" <scot@possum.in-berlin.de>
To: "Ole Jensen" <learning.python@dbmail.dk>; <tutor@python.org>
Sent: Friday, February 21, 2003 5:54 PM
Subject: Re: [Tutor] Using special characters in Python


> Hello Ole,
>
> > The problem is that in Danish (and Norwegian) we have some characters in
> > the alphabet that doesn not exist in the english one, i.e. æ, ø, and å
(in
> > case you can see them correctly here they are in html: &aelig; and
&oslash;
> > and &aring;)
>
> I have had the same problem with German Umlauts since I started with
Python.
> It is not so much due to Python, which handles non-US-characters
beautifully,
> but Tkinter, which doesn't, and keeps spitting out things like your
>
> > UnicodeError: ASCII encoding error: ordinal not in range(128)
>

Ok so thats why I can't do the special characters in IDLE (IDLE being made
from python and TKinter, I believe).

> I acutally spent the better part of an evening trying to get Tkinter to
accept
> Umlauts to use with the email.Utils.unquote() method, up to the point
where I
> was systematically testing just what encoding Tkinter was returning the
> string in (UTF-8? UTF-16? ISO-8859-1? 7-bit ASCII? Klingon?) but to no
avail.
> I ended up doing it the hard way with the older quopri module via
cStringIO,
> which is ugly, but at least works.
>
> Anyway, what has worked for me in the past (but for some reason doesn't
work
> every time) is a line such as:
>
> theinputstring = theinputstring.encode("ISO-8859-1")
>

 I don't know exectly how to use that example, as when you type it in python
doesn't know the 'theinputstring' function, is it a function you have made?
or do you need to import something to get it to work?

>>> theinputstring = theinputstring.encode("ISO-8859-1")
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in ?
    theinputstring = theinputstring.encode("ISO-8859-1")
NameError: name 'theinputstring' is not defined

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

Furthermore,  when I open up python(command line) (as my guess was I coudn't
use idle) I could without trouble use all the special characters on my
keybord, i.e. æ, ø and å.

So now I was thinking I could just write the special characters in notepad
and the run my program(that doesn't use TKinter) by double clicking the
windows icon, which opens python.exe, but it didn't work as planned.
The å's became Õ and the ø became the superscipt of o.

Strange... I don't even know what to comment on that

> Y, Scot
>
> --
>   Scot W. Stevenson -- scot@possum.in-berlin.de -- Zepernick, Germany
>

Ole