[Zope3-Users] problems deleting objects in containers

Dominique Lederer dominique.lederer at inode.at
Wed Jun 6 14:40:23 EDT 2007


Dominique Lederer wrote:
> hi
> 
> i want to delete objects in my container, for that i do
> 
> for xx in container.keys():
>   logging.info(xx)
>   del container[xx]
> 
> but only every second obj is deleted, the loop touches objects in this order:
> 1,3,5,7,.....
> 
> if i remove the del statement from the upper example, the loop works as expected:
> 1,2,3,4,5,6...

oh, ok, i should not mess arround with the container keys while deleting from
the container ;)

i fixed it with:

for xx in [key for key in container.keys()]:
  del container[xx]


More information about the Zope3-users mailing list