IDLE and non-ascii encoding workaround?

Discussion in 'Python' started by klappnase, Nov 17, 2003.

  1. klappnase

    klappnase Guest

    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 IOBinding.py into a
    try-except statement. My function now looks like this:

    def writefile(self, filename):
    self.fixlastline()
    #chars = str(self.text.get("1.0", "end-1c"))#original line
    #workaround to fix the "umlaut" problem:
    try:
    chars = str(self.text.get("1.0", "end-1c"))
    except:
    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
    try:
    f = open(filename, "w")
    f.write(chars)
    f.close()
    ## print "saved to", `filename`
    return 1
    except IOError, msg:
    tkMessageBox.showerror("I/O Error", str(msg),
    master=self.text)
    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.

    Michael
     
    klappnase, Nov 17, 2003
    #1
    1. Advertising

  2. (klappnase) writes:

    > Any hints on this would be very appreciated.


    I recommend to use the IDLE that comes with Python 2.3.

    Regards,
    Martin
     
    Martin v. =?iso-8859-15?q?L=F6wis?=, Nov 17, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bartolomé Sintes Marco

    non-ASCII characters IDLE 1.0 rc1 bugs

    Bartolomé Sintes Marco, Jul 20, 2003, in forum: Python
    Replies:
    2
    Views:
    322
    Bartolomé Sintes Marco
    Jul 20, 2003
  2. Replies:
    2
    Views:
    542
    Paul Boddie
    Oct 8, 2006
  3. TOXiC
    Replies:
    5
    Views:
    1,290
    TOXiC
    Jan 31, 2007
  4. bruce
    Replies:
    38
    Views:
    295
    Mark Lawrence
    Nov 1, 2013
  5. MRAB
    Replies:
    0
    Views:
    102
Loading...

Share This Page