http://hi.baidu.com/yanjingtu/blog/item/eaa0c011b8f9ee1db9127be5.html
http://www.python.org/dev/peps/pep-0263/(标准文档)
Python will default to ASCII as standard encoding if no other
encoding hints are given.
To define a source code encoding, a magic comment must
be placed into the source files either as first or second
line in the file, such as:
# coding=<encoding name>
or (using formats recognized by popular editors)
#!/usr/bin/python
# -*- coding: <encoding name> -*-
or
#!/usr/bin/python
# vim: set fileencoding=<encoding name> :
报错:SyntaxError: Non-ASCII character '\xef' in file qbdg.py on line 4, but no encoding declared
解决,在脚本文件开头加上:
#coding=gbk
#coding=utf-8
#-*- coding: UTF-8 -*-