[Python-Dev] Re: PEP: Defining Python Source Code Encodings
Bruce Sass
bsass@freenet.edmonton.ab.ca
Tue, 17 Jul 2001 12:31:24 -0600 (MDT)
On Tue, 17 Jul 2001, M.-A. Lemburg wrote:
<...>
> - which format to use for the magic comment, e.g.
>
> * Emacs style:
>
> #!/usr/bin/python
> # -*- encoding = 'utf-8' -*-
This should work for everyone, but will it confuse emacs?.
I suppose, "# # ...", or "### ...", or almost any short sequence
starting with "#" will work, eh.
> * Via meta-option to the interpreter:
>
> #!/usr/bin/python --encoding=utf-8
This will require editing if python is not in /usr/bin, and can not be
used to pass more than one argument to the command (python, in this
case).
> * Using a special comment format:
>
> #!/usr/bin/python
> #!encoding = 'utf-8'
This is confusing, and will only work on *nix (linux?) iff it is the
second (or later) line; if it is the first line... it will fail
because there is probably no executable named "encoding" available,
and if there is, "= 'utf8'" is unlikely to exist.
please,
Avoid character sequences that have other meanings in this context.
I think this should be done as a generic method for pre-processing
Python source before the compiler/interpreter has a look at it.
e.g.,
# ## encoding utf-8
triggers whatever you encoding fans want,
# ## format noweb
runs the source through a filter which can extract code noweb marked
up code, and maybe even installs the weaved docs and tangled code
(via distutils?)
# ## MySpecialMarkup
runs the source through a filter named MySpecialMarkup.
MySpecialMarkup could be anything: extensions to docstrings, a
proprietary binary format, an entire package-in-a-file!
Generally: #<magic> <directive> [<arguments>]
If Python does not know what the <directive> is it should either look
in a set location for a program of the same name then use its output as
the source, or look into a table that maps <directive> to a procedure
which results in Python source.
- Bruce