trouble understanding super()
John Salerno
johnjsal at NOSPAMgmail.com
Mon Jul 31 13:23:16 EDT 2006
Simon Forman wrote:
> In this case the object's (instance of D) mro will be (D, B, C, A,
> object), so as super gets called in each class, it looks in that list
> (tuple, whatever) for the class following it (actually the next class
> following it that implements the method).
>
> Since no class appears in that list more than once, each class's
> implementation of the method will only be called once.
But after super(D, self).met() is called, doesn't that then call both
super(B, self).met() and super(C, self).met()? If so, how does that
avoid calling A.met twice? Or is that not what's happening?
Here's what I think gets called, in order, after running D().met():
print 'D.met'
super(D, self).met()
print 'B.met'
super(B, self).met()
print 'A.met'
print 'C.met'
super(C, self).met()
print 'A.met'
More information about the Python-list
mailing list