[Zope] not allowed to access a particular tuple
Jonathan
dev101 at magma.ca
Fri Oct 20 09:05:32 EDT 2006
----- Original Message -----
From: "William Heymann" <kosh at aesaeion.com>
To: <zope at zope.org>
Sent: Friday, October 20, 2006 8:55 AM
Subject: [Zope] not allowed to access a particular tuple
> This is an external method I wrote to make it easier to iterate over the
> records returned from searching the catalog. However if I have
>
> yield record,item instead of yield item it says that I am not allowed to
> access a particular tuple during iteration. How can I make it so that the
> value that it yields is something that a python script object can iterate
> over? I have also tried doing yield tuple((record,item)) yield
> list(record,item) and they give the same problem.
>
>
> How I use the script is pretty much
>
> for record, doc in catalogIter(context.Catalog(searchterms)):
> print record
> print doc
>
> Of course what is inside is different from that but it will cause the same
> problem since the issue happens in the iteration not inside the for loop.
>
> import zExceptions
>
> def catalogIter(records):
> "iterate over a catalog safely"
> for record in records:
> try:
> item = record.getObject()
> if item is not None:
> yield item
> except (zExceptions.Unauthorized, zExceptions.NotFound, KeyError,
> AttributeError):
> pass
The 'yield' statement is not allowed within a 'try' clause (see the Python
Reference manual).
Why don't you just build a simple list (or list of tuples) and return that?
Jonathan
More information about the Zope
mailing list