[已解决]UnicodeWarning: Unicode equal comparison failed to conv

软件和网站开发以及相关技术探讨
回复
头像
Hello World!
帖子: 3051
注册时间: 2008-06-23 15:19
系统: ���������
来自: 北欧某国
联系:

[已解决]UnicodeWarning: Unicode equal comparison failed to conv

#1

帖子 Hello World! » 2011-10-27 12:18

我正在研究一个关卡编辑器,可是那个关卡编辑器好像对中文不太友好:

代码: 全选

/home/liu/code/panda/aMonpoly/PaletteTreeCtrl.py:41: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  if parentItemName == items[key]:
第41行,就是将两个中文字符串进行比较时,就出错了。
[python] #-*- coding: utf-8 -*-
"""
Defines Palette tree control
"""
import wx
import cPickle as pickle
from ObjectPaletteBase import *

class PaletteTreeCtrl(wx.TreeCtrl):
def __init__(self, parent, treeStyle, rootName):
wx.TreeCtrl.__init__(self, parent, style=treeStyle)

self.rootName = rootName
self.root = self.AddRoot(self.rootName)

self.paletteUI = parent

self.opSortAlpha = "Sort Alphabetical Order"
self.opSortOrig = "Sort Original Order"
self.opSort = self.opSortOrig

self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.onBeginDrag)

def OnCompareItems(self, item1, item2):
return self.paletteUI.compareItems(item1, item2)

def SortTreeNodes(self, parent):
self.SortChildren(parent)
item, cookie = self.GetFirstChild(parent)
while item:
if self.ItemHasChildren(item):
self.SortTreeNodes(item)

# continue iteration to the next child
item, cookie = self.GetNextChild(parent, cookie)

def addTreeNodes(self, parentItem, parentItemName, items, itemKeys):
roots = []
rootItems = []
for key in itemKeys:
if parentItemName == items[key]:
print parentItemName,items[key]
roots.append(key)
for root in roots:
newItem = self.AppendItem(parentItem, root)
self.SetItemPyData(newItem, root)
rootItems.append(newItem)
itemKeys.remove(root)
for rootItem in rootItems:
self.addTreeNodes(rootItem, self.GetItemText(rootItem), items, itemKeys) [/python]
问题解决了。
if parentItemName.encode('utf-8') == items[key]:
http://noie.name 网站改版中。
回复