繁体   English   中英

Python super(Class,self).method vs super(Parent,self).method

[英]Python super(Class, self).method vs super(Parent, self).method

这个问题来自以下问题 ,比方说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()

将调用do_work函数,如B的父类所见 - 即A.do_work


super(A,self).do_work()

将调用do_work函数,如A的父类所示 - 即object.do_work (可能不存在,因此可能引发异常)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM