[ZODB-Dev] Iterating through BTreeItems
Jim Fulton
jim@digicool.com
Thu, 24 May 2001 19:18:13 -0400
Andrew Kuchling wrote:
>
> 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.
In general. the repr would be counter productive, since there are
typically lots of items. I'd happily accept a patch (or maybe
later a checkin) for a repr that did the normal thing when there
weren't many values and then maybe showed some elided values when
there are more than a certain amount.
Jim
--
Jim Fulton mailto:jim@digicool.com Python Powered!
Technical Director (888) 344-4332 http://www.python.org
Digital Creations http://www.digicool.com http://www.zope.org