Harri Pasanen: Re: [Idle-dev] Known bug? Saving fails in IDLE if accents used in char acters
Harri Pasanen
harri@nerim.net
Mon, 24 Mar 2003 10:00:36 +0100
On Sunday 23 March 2003 23:33, Martin von Loewis wrote:
> > Saving my python file, still consisting of the single line
> > # déjà
> >
> > it spits out a message box with a title "I/O Error"
> > Non-ASCII found, yet no encoding declared. Add a line like
> > #-*- coding: iso-8859-15-*-
> > to your file [OK]
> >
> > After clicking OK, it seems to save my file without problems, but
> > it bugs me with the message at each save.
>
> Hi Harry,
>
> There is not much we can do about this; IDLE *could* try to edit
> the file for you, but I consider this too intrusive, hence the
> error message.
>
My vote for IDLE inserting the font encoding line to top of file if it
does not exist.
> > The message box is modal, and I cannot cut and paste the line
> > from it.
>
> Patches to correct this are welcome. I'm unsure what Tk widget to
> use that allows copyable-but-uneditable text.
>
> > Typing it in manually, my next I/O Error is:
> >
> > Unknown encoding iso-8859-15-.
> > Saving as UTF-8
> > [OK]
>
> Are you sure there was no space between the 5 and the - in the
> message? Adding a space should help.
You are right, the space helps. But having manually to type the
encoding line is prone to errors, that is why I think editors should
have built in support for templating that sort of things.
Note that the message box is also in a proportional, not fixed font,
so spotting the spaces is not obvious.
> [snip...]
> Indeed; this is the result of PEP 263. Unlike Perl, Python supports
> multiple different source encoding, hence the need for an explicit
> declaration.
>
> > Now how about doing what 99% of other editors do, and supporting
> > by default iso-8859-15 (basically latin-1), that will make get a
> > couple of hundred million Europeans happy right there?
>
> Supporting this in IDLE would be acceptable, I guess. However, in
> the long run, Python itself will refuse source code that lacks a
> proper encoding declaration, so I felt that IDLE should teach users
> how to do that early on.
>
But the PEP states:
1. Allow non-ASCII in string literals and comments, by internally
treating a missing encoding declaration as a declaration of
"iso-8859-1".
The current IDLE or IDLEfork does not seem to do above. And what
about maintaining legacy python code with IDLE, much of which is in
is-8859-1 I suppose?
> > Extending the support outside of latin alphabets is an honorable
> > goal, but clearly what ever the encoding is should not munge with
> > the python source code, unless python itself has support for it.
>
> But Python does have support for it.
>
Starting from 2.3 I understand?
Thanks for the explanations, PEP 263 is good news to me.
Harri