python2.7运行出现的Warning: UnicodeWarning: Unicode equal comparison failed to convert both arguments to ...

运行出现如下错误

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

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

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

 

import sys  
  
reload(sys)  
sys.setdefaultencoding('utf8')  

 

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

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

  

转载于:https://www.cnblogs.com/robinunix/p/9019874.html

你可能感兴趣的:(python2.7运行出现的Warning: UnicodeWarning: Unicode equal comparison failed to convert both arguments to ...)