【发布时间】:2016-03-21 19:56:25
【问题描述】:
有这样的对象
class testDec(object):
def __init__(self):
self.__x = 'stuff'
@property
def x(self):
print 'called getter'
return self.__x
@x.setter
def x(self, value):
print 'called setter'
self.__x = value
为什么我不能设置属性__x?这是一个回溯
>>> a.x
called getter
'stuff'
>>> a.x(11)
called getter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable
我使用的是 2.7.6 Python
【问题讨论】:
-
如果你想设置
a.x,你不应该设置a.x = 11吗?
标签: python properties