PEP-0263 and default encoding

Bengt Richter bokr at oz.net
Wed Oct 1 18:43:40 EDT 2003


On 30 Sep 2003 23:40:53 +0200, martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) wrote:

>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.
>
How about letting someone in Klaus' situation be explicit in another way? E.g.,

    python -e iso-8859-1 the_unmarked_source.py

Hm, I guess to be consistent you would have to have some way to pass -e info
into any text-file-opening context, e.g., import, execfile, file, open, etc.
In such case, you'd want a default. Maybe it could come from site.py with
override by python -e, again with override by actual individual file-embedded
encoding info.

But being the encoding guru, you have probably explored all those thoughts and
decided what you decided ;-) Care to comment a little on the above, though?

>> 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.
That's not the same as giving a proper encoding interpretation, is it?
(Though in comments it wouldn't matter much).

>
>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.
YMMV with the editor you are using though, right?

>
>In neither case, relying on the system default encoding is necessary.
Hm, for python -e to work, I guess all the library stuff would have to
be explicitly marked, or the effect would have to be deferred.
Hm2, is all internal text representation going to wind up wchar at some point?

Regards,
Bengt Richter




More information about the Python-list mailing list