我已经设置了gtk.TreeView
一个gtk.TreeStore
。一列包含格式化的美元金额,我已按该列设置排序如下:
def sortmon(model, i1, i2):
v1 = model[i1][COL_MONEY]
v2 = model[i2][COL_MONEY]
return cmp(float(v1.replace("$","").replace(",","")),
float(v2.replace("$","").replace(",","")))
self.hsModel.set_sort_func(COL_MONEY, sortmon)
这很好用,除了有时,当我追加一行时,我得到:
stderr : INFO Traceback (most recent call last):
stderr : INFO File "C:\Users\DrClaud\bumhunter\gui\widgets\replay\ReplayWidget.py", line 141, in sortpot
stderr : INFO float(v2.replace("$","").replace(",","")))
stderr : INFO AttributeError: 'NoneType' object has no attribute 'replace'
我做了更多的打印输出,似乎当我插入一行时,其中一个model[i1][x]
或model[i2][x]
任何 x 将是无。我确定我没有插入包含None
元素的行。那么会发生什么?