Quick question about Python(ic) inheritence: what is the difference between the idiom posted here (super(ChildClass,self).method(args)) vs. the one on the Python docs site (ParentClass.method(self,[args]))? Is one more Pythonic than the other?
Quick question about Python(ic) inheritence: what is the difference between the idiom posted here
Share
Using
super(ChildClass, self).method(args)allows you to walk the method resolution order and — if everyone but the last parent usessuper— call every class in the hierarchy exactly once. (Not thatsuperonly works with new-style classes.)Using
ParentClass.method(self, args)calls one specific class. It does not work when involved in multiple inheritance.This article provides some description of the issue and clarifies a lot of issues for some people. I don’t agree with all of its conclusions, but it provides good examples and discussion.