基本的には、私が持っている問題はhereであり、Son
はFather
(この場合はinit)やGrandFather
(do_thing
)のようなものをいくつか返すことがあります。自分以外のクラスの型を渡す、すなわち、その(上記の最後の行)のようなsuper
を呼び出すに何らかの影響があるかどうか、私は疑問に思って何親の親の方法を呼び出すと、結果は何か?
class GrandFather(object):
def __init__(self):
pass
def do_thing(self):
# stuff
class Father(GrandFather):
def __init__(self):
super(Father, self).__init__()
def do_thing(self):
# stuff different than Grandfather stuff
class Son(Father):
def __init__(self):
super(Son, self).__init__()
def do_thing(self):
super(Father, self).do_thing() # <-- this line bypasses Father's implementation
です。 私はあなたのコードがあなたがそれを期待していない奇妙な点で壊れているようなものを意味します。
未対応のものについては、こちら(http://stackoverflow.com/questions/5033903/python-super-method-and-calling-alternatives)、[こちら](http://stackoverflow.com/questions)/222877/what-do-super-do-in-python)または[ここ](http://stackoverflow.com/questions/576169/understanding-python-super-with-init-methods)? –
@StephenRauch何がカバーされていませんか?私の質問はカバーされていません! :D私の例の最後の行が 'super(Son、self)'ではなく 'super(Father、self)'を読み込んでいることに注目してください。後者は 'super'を使う普通の方法です。これはあなたが提供したリンクでカバーされています。私の質問は、私は直接親クラスをバイパスし、祖父母クラスのメソッドを呼び出す前者についてです! – Mahdi