IDLE and non-ascii encoding workaround?

klappnase klappnase at
Mon Nov 17 02:40:14 CET 2003

Hello everyone,

there have already been a couple of threads about IDLE's sometimes
annoying disability to use special characters (in my case I would like
to use for example german umlauts like "ä" etc.).
I have made a workaround that *seems* to work, so I can at least store
files in the editor that use such characters ( on the python shell I
still get:

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

but that does not matter much to me).
However I don't know very much about encoding issues, so maybe someone
can tell me if there might be problems that I don't see at the moment.
Here's what I did:

I changed one line in the writefile function in into a
try-except statement. My function now looks like this:

    def writefile(self, filename):
        #chars = str(self.text.get("1.0", "end-1c"))#original line
        #workaround to fix the "umlaut" problem:
            chars = str(self.text.get("1.0", "end-1c"))
            c = self.text.get("1.0", "end-1c")
            chars = ''
            for i in c:
                j = ord(i)
                k = chr(j)
                chars = chars + k
            chars = str(chars)
        #end of workaround
            f = open(filename, "w")
            ## print "saved to", `filename`
            return 1
        except IOError, msg:
            tkMessageBox.showerror("I/O Error", str(msg),
            return 0

This may take a few seconds if you want to save a large file, but at
least it is better as if it wasn't possible at all.

Any hints on this would be very appreciated.
Thanks in anticipation.


More information about the Python-list mailing list