运行出现如下错误

uncode编码警告:在unicode等价比较中,把两个参数同时转换为unicode编码失败。中断并认为他们不相等。

windows下的字符串str默认编码是ascii,而python编码是utf8

解决方法:添加如下几行代码

import sys  

reload(sys)
sys.setdefaultencoding('utf8') 或者
if sys.getdefaultencoding() != 'utf-8':
reload(sys)
sys.setdefaultencoding('utf-8')

该解决方法同样适用于如下报错

ascii' codec can't decode byte 0xe6 in position 31: ordinal not in range(128)

  

python2.7运行出现的Warning: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal的更多相关文章

  1. python2.7运行报警告:UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal解决办法

    1. 程序源代码报错部分: #选择年级if grade == '幼升小': outline.nianji().pop(0).click()elif grade == "一年级": ...

  2. Python——UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal

    当字符串比较中有中文时,需要在中文字符串前加 u  转为unicode编码才可以正常比较. str == u"中文"

  3. 关于在2.7中出现 "UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal"

    在中文字符串前面加u. Make sure your code is in UTF-8 (NOT Latin-1) and/or use a coding line as so: #! /usr/bi ...

  4. python2.7运行selenium webdriver api报错Unable to find a matching set of capabilities

    在火狐浏览器33版本,python2.7运行selenium webdriver api报错:SessionNotCreatedException: Message: Unable to find a ...

  5. WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

    在 mkfs.ext4 /dev/sda2 格式化硬盘空间时,可能出现这种错误. had this situation at office where I was told to re-partiti ...

  6. 运行easy_install安装python相关程序时提示failed to create process

    运行easy_install安装python相关程序时提示failed to create process,因为安装了两个python,卸载了的那个目录没删除,删除了另外的python目录后这个问题就 ...

  7. failed (1113: No mapping for the Unicode character exists in the target multi-byte code page), client: 127.0.0.1...

    nginx部署网站后,访问域名,网页显示  500 Internal Server Error ,经查看发现nginx的error.log中有报错: failed (1113: No mapping ...

  8. Xhprof graphviz Warning: proc_open() [function.proc-open]: CreateProcess failed, error code 解决方法

    Xhprof在windows下点击[View Full Callgraph]调用graphviz软件时.警告Warning: proc_open() [function.proc-open]: Cre ...

  9. WARNING: Re-reading the partition table failed with error 22: Invalid argument

    在划分磁盘分区时,遇到错误"WARNING: Re-reading the partition table failed with error 22: Invalid argument&qu ...

随机推荐

  1. 用gulp把less文件编译成css文件

    第一次使用gulp构建工具,使用gulp将.less文件编译成.css文件并输出.根据视频做了笔记.提供新手和自己以后做参考. HTML文件 <!DOCTYPE html> <htm ...

  2. JavaScript 常用的排序算法

    冒泡排序 function bubbleSort(array) { for (let i = 0; i < array.length; i++) for (let j = 0; j < a ...

  3. linux正则表达式基础部分

    1.什么是正则表达式? 简单的说,正则表达式就是为处理大量的字符串而定义的一套规则和方法, 例如:假设“@”代表boy,“!”代表girl.echo“@!” === “boygirl” 通过定义的这些 ...

  4. jQuery实现复选框的全选、反选功能

    <ul id="list"> <li><label><input type="checkbox" value=&quo ...

  5. hdu 5667

    Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  6. Spark MLlib(下)--机器学习库SparkMLlib实战

    1.MLlib实例 1.1 聚类实例 1.1.1 算法说明 聚类(Cluster analysis)有时也被翻译为簇类,其核心任务是:将一组目标object划分为若干个簇,每个簇之间的object尽可 ...

  7. BZOJ 4393: [Usaco2015 Dec]Fruit Feast

    DP #include<cstdio> using namespace std; int T,A,B,F[5000005],G[5000005]; int main(){ scanf(&q ...

  8. 【Partition List】cpp

    题目: Given a linked list and a value x, partition it such that all nodes less than x come before node ...

  9. leetcode 【 Remove Element 】python 实现

    题目: Given an array and a value, remove all instances of that value in place and return the new lengt ...

  10. 第1章 HTML基础

    1.1 HTML概述 1.1.1 什么是HTML HTML(Hyper Text Markup Language,超 文本 标记 语言)是纯文本类型的语言,它是Internet上用于编写网页的主要语言 ...