[Erp5-dev] Deleting a list of objects in a container
    Guillaume Michon 
    guillaume at nexedi.com
       
    Wed Jul 28 11:50:58 CEST 2004
    
    
  
Hi all,
The following code does not work as expected :
for o in container.contentValues():
   container._delObject(o.getId())
The reason is that python does not calculate the expression 
"container.contentValues()" only one time, but at each passage through the 
for. So modifying content of container changes the result of the expression. 
Then the behavior is undeterminable.
The secured way to do is to build a list of ids to delete, then delete them :
to_delete = []
for o in container.contentValues():
   to_delete.append(o.getId())
   container.deleteContent(to_delete)
Regards,
Guillaume
    
    
More information about the Erp5-dev
mailing list