[Zope] Strange property behaviour - why? (zope 2.10/Five)

Piotr Chamera piotr_chamera at poczta.onet.pl
Tue May 13 07:50:33 EDT 2008


Hello,

I don't understand property behawiour in code bellow (I am not
experienced programmmer, so I could missed something obivious).

In example bellow: "list_items1" works as I expected - it returns
list of objects from catalog but "list_items2" fails - I get Attribute 
Error or if it finds "items" through acquisition it returns this object.

But, if I uncomment line "return [1,2,3]" in code below, then both
functions return the same value - list [1,2,3].

Search of "catalog" by acquisition messes with class attribute lookup?

<code>
class Storage (SimpleItem):
     """ see IStorage interface """

     implements(IStorage)

     title = FieldProperty(IStorage['title'])
     description = FieldProperty(IStorage['description'])

     def _get_items(self):
         """ Return list of items in storage (unsorted). """
         #return [1,2,3]
         return [x.getObject() for x in self.catalog(storage=self.title)]

     items = property(_get_items)

     def list_items1(self):
         """ test """
         return self._get_items()

     def list_items2(self):
         """ test """
         return self.items
</code>

Piotr Chamera


More information about the Zope mailing list