在中文字符串前面加u.

Make sure your code is in UTF-8 (NOT Latin-1) and/or use a coding line as so:

#! /usr/bin/python
# -*- coding: utf-8 -*-
a = {"a": u"çö"}
b = "çö"
assert b == a['a']
assert b.decode('utf-8') == a['a'].decode('utf-8')

If you're using unicode across the board, you can import unicode_literals from the future and cut back on encoding heartaches:

#! /usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
a = {"a": u"çö"}
b = "çö"
assert b == a['a']
assert b == a['a']
assert b.encode('utf-8') != a['a']
assert b.encode('utf-8') == a['a'].encode('utf-8')

If a file uses unicode_literals, all "strings" are now u"unicode" objects (per the coding of the file) if they're not b"prepended" with a b (to emulate the string/bytes split in Python 3.X).

关于在2.7中出现 "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. python2.7运行出现的Warning: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal

    运行出现如下错误 uncode编码警告:在unicode等价比较中,把两个参数同时转换为unicode编码失败.中断并认为他们不相等. windows下的字符串str默认编码是ascii,而pytho ...

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

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

  4. 汉字编码(【Unicode】 【UTF-8】 【Unicode与UTF-8之间的转换】 【汉字 Unicode 编码范围】【中文标点Unicode码】【GBK编码】【批量获取汉字UNICODE码】)

    Unicode与UTF-8互转(C语言实现):http://blog.csdn.net/tge7618291/article/details/7599902 汉字 Unicode 编码范围:http: ...

  5. 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 ...

  6. How to convert a QString to unicode object in python 2?

    How to convert a QString to unicode object in python 2? I had this problem to solve, and I tried to ...

  7. Vue-cli3.x在开发环境中(router采用 history模式)出现Failed to resolve async component default: Error: Loading chunk {/d} failed.或者Uncaught SyntaxError: Unexpected token <错误

    使用Vue-cli3.x开发环境中(router采用 history模式)出现Failed to resolve async component default: Error: Loading chu ...

  8. centOS7中启动MySQL数据库提示: Failed to start mysqld.service: Unit not foundc

    现象: 在centOS7中启动MySQL数据库提示: Failed to start mysqld.service: Unit not found [明明已经安装了,为什么提示不存在呢?] 原因: 在 ...

  9. 简体和繁体加起来有六七万个汉字,所以Unicode只能排除一些几乎不用的汉字,Unicode编码的熟悉与研究过程(内附全部汉字编码列表)

    我有一个问题是:是不是会有个别汉字无法在Unicode下表示,这种情况下就不能完全显示了? 各种编码查询表:http://bm.kdd.cc/ ---------------------------- ...

随机推荐

  1. 使用@media screen解决移动web开发的多分辨率问题

    当今移动设备的发展已经越来越迅速,移动web开发的需求也越来越多多.许多大平台.大门户都纷纷推出了自己的移动web版网站. 随着移动设备飞速的发展,移动产品的屏幕规格越来越多.从几年前的320×240 ...

  2. Template、ItemsPanel、ItemContainerStyle、ItemTemplate (部分内容有待验证)

    以下摘自“CSDN”的某人博客,部分内容有待验证,需注意“辨别学之....” 1.Template是指控件的样式 在WPF中所有继承自contentcontrol类的控件都含有此属性,(继承自Fram ...

  3. IOS加载PDF文件

    今天的任务是:在iOS上加载显示pdf文件. 方法一:利用webview -(void)loadDocument:(NSString *)documentName inView:(UIWebView  ...

  4. IOS-2016年最好的15个Web设计和开发工具

    设计师和开发者,web设计师和开发者遍地开花.这促使web开发人员也需要寻找最好的工具去设计出优于其他人的网站.作为一个web设计师或开发者,你必须寻找新的途径来提高自己的技能,提高自己的工作质量.下 ...

  5. ZOJ 3696 Alien's Organ(泊松定理,期望值)

    Alien's Organ Time Limit: 2 Seconds      Memory Limit: 65536 KB There's an alien whose name is Marja ...

  6. 启动和停止Oracle服务bat脚本

    总所周知,Oracle随开机启动会占很大内存,而你每次想用的时候还得去计算机服务里去找服务.一个一个的启动,比较麻烦. 这里给出两个bat脚本,来直接双击启动和停止Oracle服务[脚本内容来源于网络 ...

  7. 使用CGLib完成代理模式遇到的错误

    错误堆栈信息: Exception in thread "main" java.lang.NoClassDefFoundError: org/objectweb/asm/Type ...

  8. python 中 property 属性的讲解及应用

    Python中property属性的功能是:property属性内部进行一系列的逻辑计算,最终将计算结果返回 property属性的有两种方式: 1. 装饰器 即:在方法上应用装饰器 2. 类属性 即 ...

  9. Linux:grub密码设置与修改

    grub密码设置与修改 默认GRUB启动参数可以的进入单用户模式从而修改root密码,如果想要给GRUB菜单设置密码,可以修改/etc/grub.conf文件 (/boot/grub/grub.con ...

  10. ROS-I工业机器人培训课程资料 2017-06-30

    美国ROS工业联盟于2017年6月6日至8日在德克萨斯州圣安东尼奥市的SwRI举办了ROS工业开发人员培训班.12位与会者代表了一系列不同的组织,包括Bastian Solutions,EWI,Joh ...