[ZODB-Dev] BTrees Bug?
Dieter Maurer
dieter at handshake.de
Wed Feb 2 15:36:02 EST 2005
Chris Withers wrote at 2005-2-2 14:59 +0000:
> ...
> >>> for key in b.keys(0,3):
>... print key
>... del b[key]
>...
>0
>2
> ...
>2. The above feels like a bug to me, even excluding the common pythonism
>of not being able to iterate over mutables if you're changing them. The
>above code is saying "gimme keys where the key is less that 3", which it
>doesn't do :-S
This is not at all BTree specific.
You get similar behaviour with a list:
for x in some_list:
some_list.remove(x)
The Python documentation clearly documents this caveat (for lists)
and suggests the right work around: copy the list before you
iterate destructively over it.
In your concrete example: this would read:
for key in list(b.keys(0,3)): ...
--
Dieter
More information about the ZODB-Dev
mailing list