'coding = utf8'和' - * - coding:utf-8 - * - '之间有什么区别? [英] What's the difference between 'coding=utf8' and '-*- coding: utf-8 -*-'?
问题描述
使用
之间是否有任何区别#coding = utf8
pre>
和
# - * - coding:utf-8 - * -
#encoding:utf-8
解决方案没有区别; Python识别所有3.它寻找模式:
编码[:=] \s *([ - \w 。] +)
文件的前两行(也必须以
#
)。
这是文字'coding',后跟冒号或等号,空白。
- * -
是一个 Emacs特定语法;让文本编辑器知道使用什么编码。它使注释对两个工具有用。 VIM支持类似语法。
Is there any difference between using
#coding=utf8
and
# -*- coding: utf-8 -*-
What about
# encoding: utf-8
解决方案There is no difference; Python recognizes all 3. It looks for the pattern:
coding[:=]\s*([-\w.]+)
on the first two lines of the file (which also must start with a
#
).That's the literal text 'coding', followed by either a colon or an equals sign, followed by optional whitespace. Any word, dash or dot characters following that pattern are read as the codec.
The
-*-
is an Emacs-specific syntax; letting the text editor know what encoding to use. It makes the comment useful to two tools. VIM supports similar syntax.See PEP 263: Defining Python Source Code Encodings.
这篇关于'coding = utf8'和' - * - coding:utf-8 - * - '之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!