Correct way to define Python source code encoding

后端 未结 6 1747
孤街浪徒
孤街浪徒 2020-11-22 12:15

PEP 263 defines how to declare Python source code encoding.

Normally, the first 2 lines of a Python file should start with:

#!/usr/bin/python
# -*- c         


        
6条回答
  •  情深已故
    2020-11-22 12:44

    If I'm not mistaken, the original proposal for source file encodings was to use a regular expression for the first couple of lines, which would allow both.

    I think the regex was something along the lines of coding: followed by something.

    I found this: http://www.python.org/dev/peps/pep-0263/ Which is the original proposal, but I can't seem to find the final spec stating exactly what they did.

    I've certainly used encoding: to great effect, so obviously that works.

    Try changing to something completely different, like duhcoding: ... to see if that works just as well.

提交回复
热议问题