【发布时间】:2013-11-08 13:07:06
【问题描述】:
我无法理解以下注释行。 这是一个python程序。
class B:
def bbb(self):
method = self.commands[0]
method(self) #I can't umderstand this line
class A(B):
def aaa(self):
print 'aaa was called'
commands = [aaa]
c = A()
c.bbb()
输出: 叫aaa
我认为上面的 aaa 方法不需要参数。 但要运行这段代码,我需要将“self”传递给 aaa 参数。为什么?有没有文档解释这个问题?这个问题属于什么类别?
非常欢迎任何简单的代码。 因为我的英语水平太低了。 所以也欢迎改进这个问题。
我在阅读cpython/Lib/distutils/cmd.py:Command.get_sub_commands()时遇到了这个问题。
感谢您的阅读。
【问题讨论】:
标签: python class methods abstract self