zoukankan      html  css  js  c++  java
  • 如何解决执行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

  • 相关阅读:
    第一章:简介
    2018年10月底新公司
    第四章:集成
    第三章:如何建模服务
    第二章:演化架构师
    第一章:微服务
    4、工厂模式
    5、单例模式
    8、模板方法模式
    3、字典介绍
  • 原文地址:https://www.cnblogs.com/yanner/p/11096104.html
Copyright © 2011-2022 走看看