的Python 2.7的Python:自動調用父功能子實例化後
我想automotically調用父對象的功能我實例化後,其子
class Mother:
def __init__(self):
pass
def call_me_maybe(self):
print 'hello son'
class Child(Mother):
def __init__(self):
print 'hi mom'
# desired behavior
>>> billy = Child()
hi mom
hello son
有沒有一種方法可以讓我做這個?
編輯,從下面的註釋:
「我應該做它在我的問題更清晰,我真正想要的是某種形式的‘自動’調用父類的方法通過的實例化單獨觸發孩子,沒有明確地從孩子那裏調用父母的方法,我希望能有這種神奇的方法,但我不認爲有這種方法。「
您正在使用哪個版本的python? – cdarke