PEP: Defining Python Source Code Encodings

phil hunt philh at comuno.freeserve.co.uk
Thu Jul 19 08:08:33 EDT 2001


On Wed, 18 Jul 2001 16:21:37 +0200, M.-A. Lemburg <mal at lemburg.com> wrote:
>Problem
>
>    In Python 2.1, Unicode literals can only be written using the
>    Latin-1 based encoding "unicode-escape". This makes the
>    programming environment rather unfriendly to Python users who live
>    and work in non-Latin-1 locales such as many of the Asian 
>    countries.

On the contrary, the python file format, *in itself* cannot make the
environment unfriendly. What does that is the combination of the
file format and the way editors respond to unicode characters.

Which leads me to the question:
If someone encodes unicode characters into a python source file in
the new way, and then another person opens the file, using a typical
programmers editor such as emacs, vi, nedit, etc, will they get any
nasty surprises?

>       5. variable names and other identifiers will be reencoded into
>          8-bit strings using the file encoding to assure backward
>          compatibility with the existing implementation
>
>          ISSUE: 
>
>              Should we restrict identifiers to ASCII ?

IMO, yes. I'm a conservative on language change.

>        Possible choices for the format:
>
>        1. Emacs style:
>
>          #!/usr/bin/python
>          # -*- coding: utf-8; -*-
>
>        2. Via a pseudo-option to the interpreter (one which is not used
>           by the interpreter):
>
>          #!/usr/bin/python --encoding=utf-8
>
>        3. Using a special comment format:
>
>          #!/usr/bin/python
>          #!encoding = 'utf-8'
>
>        4. XML-style format:
>
>          #!/usr/bin/python
>          #?python encoding = 'utf-8'

I like all of these exceptb the 2nd, where it is being done in a deliberately
non-obvious (i'm tempted to say "misleading") way. This is unpythonic, IMO.

How about introducing a pragma comment:

   #!pragma encoding = 'utf-8'

which could then be used for other similar changes?


-- 
#===== Philip Hunt == philh at comuno.freeserve.co.uk ======#
    Herbivore: effort-free public key encryption. See:
<http://www.vision25.demon.co.uk/oss/herbivore/intro.html>
        ** First software release coming soon! **






More information about the Python-list mailing list