Mixing custom __setattr__ method and properties in new style classes

L.C. Rees lcrees at gmail.com
Wed Feb 8 12:07:57 EST 2006


Can custom __setattr__ methods and properties be mixed in new style
classes?

I experimented with a new style class with both a custom __setattr__
method and a property. Attributes controlled by the __setattr__ method
work fine. When I attempt to set or get the property it raises the
error: "TypeError: _settext() takes exactly two arguments (1 given)".
This suggests that the __setattr__ may be conflicting with assignment
to the property since it doesn't seem the class name is being passed to
the property when it's created. This is the code for the property at
the end of the class definition:

    def _settext(self, txt):
        self._tree.text = txt

    def _gettext(self, txt):
        return self._tree.text

    def _deltext(self, txt):
        self._tree.text = ''

    text = property(_settext, _gettext, _deltext)




More information about the Python-list mailing list