这是super()的合法使用吗?
class A(object):
def method(self, arg):
pass
class B(A):
def method(self, arg):
super(B,self).method(arg)
class C(B):
def method(self, arg):
super(B,self).method(arg)
Run Code Online (Sandbox Code Playgroud)
谢谢.
它会起作用,但它可能会让任何试图阅读你的代码的人感到困惑(包括你,除非你特别记得它).不要忘记,如果要从特定父类调用方法,您可以这样做:
A.method(self, arg)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1976 次 |
| 最近记录: |