[ZODB-Dev] Iterating through BTreeItems

Andrew Kuchling akuchlin@mems-exchange.org
Thu, 24 May 2001 13:00:08 -0400


On Thu, May 24, 2001 at 12:59:35PM -0300, Christian Robottom Reis wrote:
>How can I find out that the items list contains? Is using items() the
>correct way to do this?

Yes, but dir() isn't what you need; that just returns a list of the
object's methods and attributes.  You have to access it like a list:

>>> t.items()
<BTreeItems object at 0x82d9478>
>>> len(t)
136
>>> t[0]
('aluminumalbulk', <Material at 82e53f0>)
>>> t[1]
('aluminumalfilm', <Material at 82db338>)

Or loop over it with a 'for' loop.  I have often wished the repr() of
a BTreeItems was a bit more helpful, but it's a trivial issue.  

--amk