【发布时间】:2015-10-12 08:41:51
【问题描述】:
我有一个 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
只有第一个打印语句出来。
问题类似于Function Not getting called,但建议的解决方案似乎不适用于此。
【问题讨论】:
-
selfthis?self作为_method2的第一个参数在哪里? -
该代码应该会给您一个错误。您可以从错误消息中学到什么?
-
this._method2(context)应该是self.,因为你的 self 是实例的名称,而不是像 Javascript 中的这样。此外,您不需要以分号结束行。