环境:Python2.7.X
Ulipad编辑器
Python文件内容:
from selenium import webdriver
browser = webdriver.Firefox()
url = "http://www.baidu.com"
print "网站 %s" % (url)
browser.get(url)
browser.quit()
执行Python文件时出现如下错误提示:
SyntaxError: Non-ASCII character '\xe7' in file on line 13, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
因为Python的默认编码是ASCII码,如果文件中含有中文,应在文件开头加上一句:
#coding=utf-8
另外要注意,如果coding和=之间有空格,如#coding =utf-8,会有错误提示:
SyntaxError: Non-ASCII character '\xe7' in file , but no encoding declared; see http://www.python.org/peps/pep-0263.html for details