Help with super()
davidh at ilm.com
Thu Jan 12 13:46:02 EST 2006
I'm having trouble with the new descriptor-based mechanisms like super()
and property() stemming, most likely, from my lack of knowledge about
how they work.
Here's an example that's giving me trouble, I know it won't work, but it
illustrates what I want to do:
_v = [1,2,3]
if self.__class__ == A:
return super(self.__class__,self).v + self._v
v = property(_getv)
_v = [4,5,6]
b = B()
What I want is for b.v to give me back [1,2,3,4,5,6], but this example
gets into a recursive infinite loop, since super(B,self).v is still
B._getv(), not A._getv().
Is there a way to get what I'm after using super()?
The idea is that I could have a chain of subclasses which only need to
redefine _v, and getting the value of v as a property would give me back
the full chain of _v values for that class and all its ancestor classes.
Thanks in advance,
More information about the Python-list