On Thu, Jul 23, 2009 at 01:41:57PM -0400, Jim Pharis wrote:
> I have a class that inherits from Persistent but also needs to hook into
> setattr and getattribute.
> class Test(Persistent)
>    ...
>   def __setattr__(self, name, val)
>   def __getattribute__(self, name)
> Before when this class inherited from object the __setattr__ and
> __getattribute__ calls were simple and straight forward with
> object.__getattribute__(name). However, now that I inherent from Persistent,
> the equivalent Persistent.__getattribute__ and Persisent.__setattr__ don't
> seem to set/get my attributes.
> Can someone help me out. What call should I be using instead?

Works For Me(TM):

    >>> from persistent import Persistent
    >>> class Test(Persistent):
    ...     def __setattr__(self, name, value):
    ...         print "setting %s to %r" % (name, value)
    ...         super(Test, self).__setattr__(name, value)
    ...     def __getattribute__(self, name):
    ...         print "getting %s" % (name)
    ...         return super(Test, self).__getattribute__(name)
    >>> apple = Test()
    >>> apple.color = 'green'
    setting color to 'green'
    >>> apple.color
    getting color

Show us your code if you want more advice.

Marius Gedminas
IBM motto: "TEN vowels? Don't you know vowels are scrd?"
                -- Linus Torvalds

Attachment: signature.asc
Description: Digital signature

Zope3-users mailing list

Reply via email to