Overriding methods in classes that use property()
Denis S. Otkidach
ods at fep.ru
Mon Apr 22 11:41:44 EDT 2002
On Mon, 22 Apr 2002, Denis S. Otkidach wrote:
DSO> EL> class A(object):
DSO> EL> def __init__(self):
DSO> EL> self._val = None
DSO> EL>
DSO> EL> def setVal(self, value):
DSO> EL> self._val = value
DSO> EL>
DSO> EL> def getVal (self):
DSO> EL> return self._val
DSO> EL>
DSO> EL> val = property(getVal, setVal)
DSO> EL>
DSO> EL> class B(A):
DSO> EL> pass
DSO> EL>
DSO> EL> class C(A):
DSO> EL> def setVal(self, value):
DSO> EL> self._val = 'Huh?'
DSO>
DSO> Simply add one line here:
DSO> val = property(getVal, setVal)
Sorry, getVal is not in current scope. The following should be
right:
val = property(A.getVal, setVal)
More information about the Python-list
mailing list