【发布时间】:2018-12-05 11:23:03
【问题描述】:
我正在尝试使用如下的属性设置器。我在这里按照示例进行操作: How does the @property decorator work?
class Contact:
def __init__(self):
self._funds = 0.00
@property
def funds(self):
return self._funds
@funds.setter
def funds(self, value):
self._funds = value
getter 工作正常
>>> contact = Contact()
>>> contact.funds
0.0
但我缺少关于二传手的一些东西:
>>> contact.funds(1000.21)
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/doctest.py", line 1315, in __run
compileflags, 1) in test.globs
File "<doctest __main__.Contact[2]>", line 1, in <module>
contact.funds(1000.21)
TypeError: 'str' object is not callable
我在这里做错了什么?
【问题讨论】:
-
contact.funds = 1000.21