'coding = utf8'和' - * - coding:utf-8 - * - '之间有什么区别? [英] What's the difference between 'coding=utf8' and '-*- coding: utf-8 -*-'?

查看:2143
本文介绍了'coding = utf8'和' - * - coding:utf-8 - * - '之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用

之间是否有任何区别

 #coding = utf8 
pre>

 # -  *  -  coding:utf-8 -  *  -  

 #encoding:utf-8 


解决方案

没有区别; Python识别所有3.它寻找模式:

 编码[:=] \s *([ -  \w 。] +)

文件的前两行(也必须以)。



这是文字'coding',后跟冒号或等号,空白。



- * - 是一个 Emacs特定语法;让文本编辑器知道使用什么编码。它使注释对两个工具有用。 VIM支持类似语法



请参阅PEP 263:定义Python源代码编码


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆