I have some python code that's throwing a KeyError exception. So far I haven't been able to reproduce outside of the operating environment, so I can't post a reduced test case here.
The code that's raising the exception is iterating through a loop like this:
for k in d.keys():
if condition:
del d[k]
The del[k]
line throws the exception. I've added a try/except
clause around it and have been able to determine that k in d
is False, but k in d.keys()
is True.
The keys of d
are bound methods of old-style class instances.
The class implements __cmp__
and __hash__
, so that's where I've been focusing my attention.
k
is causing the problems, why don't you just see whether it exist ind.keys()
and ind
?k in d
is true butk in d.keys()
is false? I.e. the iteration is irrelevant to the issue?__hash__
function as well?