[Zope] deleting while iterating over ObjectManager
Oliver Bleutgen
myzope@gmx.net
Mon, 21 Oct 2002 20:38:46 +0200
John Hunter wrote:
> Is it safe to delete instances while iterating over the contents of an
> ObjectManager instance, as in:
>
> for item in folder.objectValues():
> if some_condition:
> folder.manage_delObjects(item.getId())
> break
> do_something(item)
>
1. store the list beforehand, just to be sure.
2. use objectItems since it contains the (id, object) tuple you need
item_list = folder.objectItems()
for item in item_list:
if some_condition:
folder.manage_delObjects(item[0])
break
do_something(item[1])
HTH,
oliver