首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

python字符串不能比较解决方案

2012-08-13 
python字符串不能比较s1self.choice14.GetStringSelection().encode(utf-8)y[是.decode(utf-8),

python字符串不能比较
s1=self.choice14.GetStringSelection().encode('utf-8')
  y=['是'.decode('utf-8'),'否'.decode('utf-8')]
  if s1==y[0]:
  t8='1'
  else:
  t8='0'

File "D:\程序\python\lionogram_measure.py", line 3778
  if s1==y[0]:
UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal

[解决办法]

探讨
在比较的时候,编码要一致:
'是'.decode('utf-8') #这是unicode编码

而:s1=self.choice14.GetStringSelection().encode('utf-8') #这是utf8编码
要比较就这样吧:

s1=self.choice14.GetStringSelection().encode('utf-8')
y=[u'是'.encode(……

热点排行