# -*- coding:utf-8 -*-
問題就來了,爲何要如此聲明? html
首先請參考python的PEP http://www.python.org/dev/peps/pep-0263/ python
概要以下 正則表達式
1.必須將編碼註釋放在第一行或者第二行 vim
2.可選格式有 編輯器
# coding=<encoding name>
#!/usr/bin/python # -*- coding: <encoding name> -*-
#!/usr/bin/python # vim: set fileencoding=<encoding name> :
#!/usr/bin/python # vim: set fileencoding=<encoding name> :
後來想了想,看了下VIM中對python的語法高亮文件,裏面把以下的正則表達式肯定爲編碼聲明 編碼
\%^.*\(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$
可是爲何一般這種方式呢? spa
# -*- coding:utf-8 -*-
話說PEP裏面不少東西都是很值得參考的畢竟能夠知道爲何程序這樣設計。 .net
相關參考 設計
PEP-0263 unix
http://www.python.org/dev/peps/pep-0263/
vim語法文件編寫總結
http://www.cnblogs.com/kohpoll/archive/2012/08/04/2623483.html
# -*- coding: UTF-8 -*- 這是個註釋嗎?
http://bbs.chinaunix.net/thread-590066-1-1.html