PEP-0263 and default encoding

Martin v. Löwis martin at v.loewis.de
Tue Sep 30 17:40:53 EDT 2003


Klaus Alexander Seistrup <rasmus.klump at myorange.dk> writes:

> And while I understand the problem, I cannot fathom why Python
> doesn't simply rely on the encoding I have specified in site.py,
> which then calls sys.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. At the time, the most
common comment was that Python should just reject any user-defined
encoding, and declare that source code files are always UTF-8,
period. The PEP gives some more flexibility over that position.

Methodically, requiring the encoding to be declared in the source code
is a good thing, as it allows to move code around across systems,
which would not be that easy if the source encoding was part of the
Python installation. Explicit is better than implicit.

> Would anyone care to explain why the community has chosen to
> inconvenience the user for each python script with non-ASCII
> characters, rather than using the default encoding given in the
> site.py configuration file?

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. Just silence the warning in site.py.

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.

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

Regards,
Martin




More information about the Python-list mailing list