[Python-Dev] PEP 263 -- Python Source Code Encoding

Jason Orendorff jason@jorendorff.com
Fri, 1 Mar 2002 21:19:27 -0600


The problem I have with PEP 263 right now is that the
"-*- coding: -*-" magic is really sort of being abused.

I gather that "coding:" is supposed to specify the
encoding (what MIME calls "charset") of the file.
But under PEP 263, it only refers to the Unicode string
literals within the program.  Everything else must still
be treated as 8-bit text.

For example, I'm not sure what effect "coding: utf-16"
would have.  (?)

For another example, if you have UTF-8 Unicode string
literals in your program but you also have 8-bit
Latin-1 plain str string literals in the same program,
how should you mark it?  How will Emacs then treat it?

Is a Python program an 8-bit string or a Unicode string?
Right now, although perhaps someone who knows more about
the parser than I can expand on this, it seems that
Python programs are 8-bit strings.  Therefore I argue
that it makes no sense to use "coding:" to label a
Python file, because the file doesn't consist of
Unicode text.

## Jason Orendorff    http://www.jorendorff.com/