[ZODB-Dev] lazy BTreeItems
Victor Safronovich
vsafronovich at naumen.ru
Sat Dec 10 03:21:25 EST 2005
Hello Dieter Maurer,
Saturday, December 10, 2005, 12:32:35 AM, you wrote:
DM> l = range(10)
DM> for f in l: l.remove(f)
DM> l
-->> [1, 3, 5, 7, 9]
DM> Due to the much more complex BTree structures, the results
DM> of modifications during iteration might be even more surprising.
I know about this
Hello Tim Peters,
Saturday, December 10, 2005, 1:08:55 AM, you wrote:
TP> The .keys(), .values(), and .items() methods of BTrees are very different
TP> from those methods on dicts in that the BTree methods return lazy iterators
TP> but the dict methods return lists.
I undestand that i need keys|values|items cast to list, and from this new list
get the new iterator.
And a funny situation
Starting debugger (the name "app" is bound to the top-level Zope object)
>>> from OFS.ObjectManager import ObjectManager
>>> from OFS.SimpleItem import SimpleItem
>>> m = ObjectManager()
>>> m._setObject('1',SimpleItem())
'1'
>>> m._setObject('2',SimpleItem())
'2'
>>> o_ids = m.objectIds()
>>> o_ids
['1', '2']
>>> m._delObject('1')
>>> o_ids
['1', '2']
>>> from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2
>>> m = BTreeFolder2()
>>> m._setObject('1',SimpleItem())
'1'
>>> m._setObject('2',SimpleItem())
'2'
>>> o_ids = m.objectIds()
>>> o_ids
<OOBTreeItems object at 0x4015dca0>
>>> list(o_ids)
['1', '2']
>>> m._delObject('1')
>>> list(o_ids)
['2']
I`ll want to migrate my large object containers from Folder to BTreeFolder2, but my
code have many next places:
for id in container.objectIds():
if some_condition:
container._delObject(id)
or
container.manage_delObjects( container.objectIds() )
Be careful with migration of such type.
--
Best regards,
Victor Safronovich
NauMen.NauDoc.SoftwareDeveloper http://www.naumen.ru
More information about the ZODB-Dev
mailing list