[Zope] Deleting several items from BTrees
Thomas Guettler
Thomas Guettler <thomas@thomas-guettler.de>
Mon, 7 Apr 2003 17:17:53 +0200
Hi!
I had problems to delete all entries from a BTree.
The working code is now:
(self.objects is a BTreeFolder2)
def deleteAllObjects(self):
"docstring"
keys=[]
for k in self.objects.keys():
keys.append(k)
len_keys=len(keys)
i=0
for k in keys:
self.objects[k].deleteObject()
i+=1
ret=[]
ret.append(self.standard_html_header())
ret.append("All objects where deleted %s %s" % (len_keys, i))
ret.append(self.standard_html_footer())
return ''.join(ret)
This does not work:
for k in self.objects.values():
k.deleteObject() # k gets deleted from self.objects
since deleting while iterating does not work.
This code does not look very nice. Is there a better way? It would be
nice to use just on loop.
thomas
--
Thomas Guettler <guettli@thomas-guettler.de>
http://www.thomas-guettler.de