PEP-0263 and default encoding

Klaus Alexander Seistrup spam at magnetic-ink.dk
Wed Oct 1 07:55:47 EDT 2003


Martin v. Löwis skrev:

>> I cannot fathom why Python doesn't simply rely on the encoding
>> I have specified in site.py, which then calls setdefaultencoding().
>
> There are several reasons. Procedurally, there was no suggestion
> to do so while the PEP was being discussed, and it was posted both
> to comp.lang.python and python-dev several times.

It's a pity I didn't read c.l.python at that time, or I would have
protested.

> It is not clear to my why you want that. There are several
> possible rationales:
>
> 1. You are have problem with existing code, and you are annoyed
>    by the warning.

Yes, I literally have hundreds of scripts with non-ASCII characters
in them - even if it's just in the comments.  Scripts that ran
silently, e.g. from crond.  Now I have to manually correct each and
every script, even if I have stated in site.py that the default
encoding is iso-8859-1.

> Just silence the warning in site.py.

Where and how in site.py can I do that?

> 2. You are writing new code, and you are annoyed by the encoding
>    declaration. Just save your code as UTF-8, using the UTF-8 BOM.

Would that help?  I put a BOM in a python script just to test your
suggestion, and I got an unrelated exception: "SyntaxError: EOL
while scanning single-quoted string".  That's even worse than a
DeprecationWarning.

> In neither case, relying on the system default encoding is necessary.

I'd prefer Python to rely on the system default encoding unless I
have explicitly stated that the script is written using another
encoding.


  // Klaus

-- 
 ><> 	unselfish actions pay back better




More information about the Python-list mailing list