正如标题所说,你怎么记得super论证的顺序?我错过了什么地方的助记符?
经过多年的Python编程,我仍然要查找它:(
(记录,它是super(Type, self))
FMc*_*FMc 11
继承让我想到了一个分类层次结构.并且参数的顺序super是分层的:首先是类,然后是实例.
另一个想法,灵感来自~unutbu的答案:
class Fubb(object):
def __init__(self, *args, **kw):
# Crap, I can't remember how super() goes!?
Run Code Online (Sandbox Code Playgroud)
建立正确super()呼叫的步骤.
__init__(self, *args, **kw) # Copy the original method signature.
super(Fubb).__init__(self, *args, **kw) # Add super(Type).
/
-------
/
super(Fubb, self).__init__(*args, **kw) # Move 'self', but preserve order.
Run Code Online (Sandbox Code Playgroud)