[Zope3-Users] object has no attribute '_SampleContainer__data'

Gary Poster gary at zope.com
Mon Oct 3 20:56:30 EDT 2005


On Oct 3, 2005, at 9:29 PM, Leticia Larrosa wrote:
> AttributeError: 'Service' object has no attribute  
> '_SampleContainer__data'

Hi Leticia.  It looks like your container overrides __init__ and,  
rather than deferring to the SampleContainer.__init__, you are trying  
to set the __data value in your own class.  If you are not familiar  
with the magic pseudo-private '__*' behavior in Python, maybe you  
should read up on it.  The immediate fix, though, is to change your  
current SampleContainer __init__.

If now it looks something like this:

class SampleContainer(BTreeContainer):
     # ...
     def __init__(self):
         # ...
         self.__data = self._newContainerData()
         # ...

then delete than instantiation and instead do this:

class SampleContainer(BTreeContainer):
     # ...
     def __init__(self):
         # ...
         super(SampleContainer, self).__init__() # this replaces the  
self.__data line
         # ...

That should hopefully clear it up.

If you need to change what is made as the data object, override  
_newContainerData (although that's where the btree mix in does its  
work!).

Gary


More information about the Zope3-users mailing list