Help with super()

Paul McNett p at ulmcnett.com
Fri Jan 13 02:10:12 CET 2006


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


-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com




More information about the Python-list mailing list