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

  • 相关阅读:
    uva-321-暴力枚举-隐式图搜索
    uva-704-暴力枚举-双向bfs
    整数的无符号编码和有符号编码
    HDU 5793
    HDU 5730
    HDU 5740
    HDU 5768
    HDU 1194
    HDU 1086
    HDU 5145
  • 原文地址:https://www.cnblogs.com/yanner/p/11096104.html
Copyright © 2011-2022 走看看