[Zope-dev] Re: Unexpected Behaviour iterating over catalog search...
Tres Seaver
tseaver at zope.com
Fri Mar 5 07:50:18 EST 2004
Chris Withers wrote:
> I have something like this:
>
> for brain in Catalog(some_index=some_value):
> # delete the object, and then
> Catalog.uncatalog_object(brain.getPath())
>
> ...which wasn't deleting all objects where some_index=some_value.
>
> On a hunch, I tried:
>
> for brain in tuple(Catalog(some_index=some_value)):
> # delete the object, and then
> Catalog.uncatalog_object(brain.getPath())
>
> ...which magically worked.
>
> Surely the thing returned by a Catalog search should be immutable?
Nope, it is "lazy"; immutability would require "realizing" it first,
which would be prohibitively expensive in many cases. Wrapping 'list()'
around the result set would've worked, too.
Tres.
--
===============================================================
Tres Seaver tseaver at zope.com
Zope Corporation "Zope Dealers" http://www.zope.com
More information about the Zope-Dev
mailing list