Newbie: Inheritance of accessors
Will Fitzgerald
fitzgerald at inetmi.com
Wed Oct 16 08:58:51 EDT 2002
It turns out the trick is to call the __init__ method on the parent
class, so the code goes:
class R(object):
def __init__(self):
self.__x = 0
def getx(self):
return self.__x
def setx(self,x):
self.__x = x
x = property(getx,setx)
class S(R):
def __init__(self):
self.__y = 0
R.__init__(self) # <=== The magic happens here
def gety(self):
return self.__y
def sety(self,y):
self.__y = y
y = property(sety,sety)
>>> e = S()
>>> e.x
0
(Thanks, again, to Mark McEahern)
More information about the Python-list
mailing list