我完全被这个难住了:
我有以下python代码:
def remove(self, widgets):
for widget in widgets:
widget_found = False
for widget_sig in self.widgets:
if widget_sig.id == widget:
#remove all objects from selected widget
widget_found = True
to_remove = widget_sig.objs
for obj in to_remove:
#objs are all intances of oo_canvas classes
obj.destroy()
self._build(widget, obj)
if not widget_found:
#if we iterated through the entire list and still couldn't find anything
raise mockingbird_errs.InternalMockingbirdError("The requested widget was not registered with this builder: "+str(widget))
这应该很简单。问题是,它永远不会正确地遍历 to_remove。出于某种原因,它会跳过所有其他元素。更令人费解的是,如果我让它在 for 循环之前和之后打印 to_remove 的长度,它会打印 254 和 127。嗯?据我所知,遍历列表并不涉及删除所有其他元素。
我错过了一些简单的东西吗?到底是怎么回事?