Help with super()

David Hirschfield davidh at ilm.com
Thu Jan 12 20:13:40 EST 2006


Yes, indeed that does work.
I tried using __mro__ based on some code that showed how super() works 
in pure-python, but I got lost.
I think this makes that clear...tho' I hate squishing around in instance 
innards like this...

Thanks a bunch, I'm sure I'll have more questions,
-Dave

Paul McNett wrote:

> David Hirschfield wrote:
>
>> Is there a way to get what I'm after using super()?
>
>
> Probably.
>
>
>> 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.
>
>
> Does this work? :
>
> class A(object):
>   _v = [1,2,3]
>
>   def _getv(self):
>     ret = []
>     mroList = list(self.__class__.__mro__)
>     mroList.reverse()
>     for c in mroList:
>       print c, ret
>       if hasattr(c, "_v"):
>         ret += c._v
>     return ret
>
>   v = property(_getv)
>
>
> class B(A):
>   _v = [4,5,6]
>
> b = B()
>
> print b.v
>
>

-- 
Presenting:
mediocre nebula.




More information about the Python-list mailing list