我有一個python類和幾個函數,第一次調用2nd。但是,第二個從來沒有被召喚過。另外調用_method2()
之後的行永遠不會執行。類內部函數不叫
class call_methods():
def _method1(self, context):
print "Now call method 2";
this._method2(context);
print "Finish";
return {}
def _method2(self, context={}):
print "method 2 called"
return {}
輸出:
Now call method 2
只有第1次印刷陳述出來。
該問題類似於Function Not getting called,但解決方案建議,似乎並不適用於此。
'self' <-->'this'? '_method2'的'self'作爲第一個參數在哪裏? –
該代碼應該給你一個錯誤。你能從錯誤信息中學到什麼? –
'this._method2(context)'應該是'self.',因爲你的self是實例的名稱,而不是像Javascript那樣。另外,您不需要用分號結束行。 –