【发布时间】:2016-09-03 14:17:24
【问题描述】:
我有一个班级比赛:
class Match(object):
def __init__(self,id):
self.id = id
def result(self):
# somehow find the game result
self.result = result
return self.result
如果我将匹配对象初始化为
m = Match(1)
当我调用我得到的方法结果时
m.result
Out[18]: <bound method Match.result of <football_uk.Match object at 0x000000000B0081D0>>
当我用括号调用它时,我得到
m.result()
Out[19]: u'2-3'
这是正确的答案。但是,当我尝试调用第二次、第三次、第四次等方法时,我得到了
m.result()
Traceback (most recent call last):
File "<ipython-input-20-42f6486e36a5>", line 1, in <module>
m.result()
TypeError: 'unicode' object is not callable
如果现在我调用不带括号的方法,它可以工作:
m.result
Out[21]: u'2-3'
与其他类似方法相同。
【问题讨论】:
标签: python