如何解决执行Python文件时出现but no encoding declared


环境: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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM