Re: [Zope-dev] Re: Unexpected Behaviour iterating over catalog search...
Jean Jordaan wrote: for brain in Catalog(some_index=some_value): # delete the object, and then brain_to_delete = Catalog(unique_index=brain.unique_prop) Catalog.uncatalog_object(brain_to_delete.getPath()) .. can't really think why that would work if Chris's original doesn't, though. ...it won't, this is analagous to the code I have that fails. cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ Zope-Dev maillist - [EMAIL PROTECTED] http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] Re: Unexpected Behaviour iterating over catalog search...
Jean Jordaan wrote at 2004-3-8 16:33 +0200: >>> 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. > >Yes .. thing is, wrapping with list() or tuple() will therefore >also be prohibitive in those cases, When you want to uncatalog everything, "tuple"ing the result should not be a problem. Otherwise, a standard approach is to remember the objects you want to delete in a standard list and iterate over this list in a separate loop (outside the first one). -- Dieter ___ Zope-Dev maillist - [EMAIL PROTECTED] http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] Re: Unexpected Behaviour iterating over catalog search...
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. Yes .. thing is, wrapping with list() or tuple() will therefore also be prohibitive in those cases, so can't be done routinely. In those cases, what would be better? Something like for brain in Catalog(some_index=some_value): # delete the object, and then brain_to_delete = Catalog(unique_index=brain.unique_prop) Catalog.uncatalog_object(brain_to_delete.getPath()) .. can't really think why that would work if Chris's original doesn't, though. -- Jean Jordaan http://www.upfrontsystems.co.za /courses.html<-- Zope/Plone training! /kursusse.html ___ Zope-Dev maillist - [EMAIL PROTECTED] http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
[Zope-dev] Re: Unexpected Behaviour iterating over catalog search...
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[EMAIL PROTECTED] Zope Corporation "Zope Dealers" http://www.zope.com ___ Zope-Dev maillist - [EMAIL PROTECTED] http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )