Overriding methods in classes that use property()

Denis S. Otkidach ods at fep.ru
Mon Apr 22 11:24:23 EDT 2002


On Mon, 22 Apr 2002, Edmund Lian wrote:

EL> When I run the code appended below, class B inherits all the
EL> methods of
EL> class A, including the property() definition as I would
EL> expect.
EL> Unfortunately, class C also does the same; I cannot override
EL> class A's
EL> setVal method. Is this a bug, or do I have to do something
EL> different (and
EL> unexpected) with Python 2.2's new style classes?
EL>
EL> ...Edmund.
EL>
EL> class A(object):
EL>     def __init__(self):
EL>         self._val = None
EL>
EL>     def setVal(self, value):
EL>         self._val = value
EL>
EL>     def getVal (self):
EL>         return self._val
EL>
EL>     val = property(getVal, setVal)
EL>
EL> class B(A):
EL>     pass
EL>
EL> class C(A):
EL>     def setVal(self, value):
EL>         self._val = 'Huh?'

Simply add one line here:
        val = property(getVal, setVal)






More information about the Python-list mailing list