Correct way to define Python source code encoding

后端 未结 6 1768
孤街浪徒
孤街浪徒 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:49

    I suspect it is similar to Ruby - either method is okay.

    This is largely because different text editors use different methods (ie, these two) of marking encoding.

    With Ruby, as long as the first, or second if there is a shebang line contains a string that matches:

    coding: encoding-name
    

    and ignoring any whitespace and other fluff on those lines. (It can often be a = instead of :, too).

提交回复
热议问题