[英]Python super(Class, self).method vs super(Parent, self).method
This question is derive from the following question , let's say class B
extends class A
这个问题来自以下问题 ,比方说class B
class A
扩展了class A
class A(object):
def do_work(self):
print 123
class B(A):
def do_work(self):
super(B,self).do_work() # versus the next statement
super(A,self).do_work() # what's the difference?
super(B,self).do_work()
will call the do_work
function as seen by the parent class of B
- that is, A.do_work
. 将调用do_work
函数,如B
的父类所见 - 即A.do_work
。
super(A,self).do_work()
will call the do_work
function as seen by the parent class of A
- that is, object.do_work
(which probably doesn't exist, and thus would likely raise an exception). 将调用do_work
函数,如A
的父类所示 - 即object.do_work
(可能不存在,因此可能引发异常)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.