I'm trying to use new-style properties declaration:
class C(object):
def __init__(self):
self._x = 0
@property
def x(self):
print 'getting'
return self._x
@x.setter
def set_x(self, value):
print 'setting'
self._x = value
if __name__ == '__main__':
c = C()
print c.x
c.x = 10
print c.x
and see the following in console:
pydev debugger: starting
getting
0
File "\test.py", line 55, in <module>
c.x = 10
AttributeError: can't set attribute
what am I doing wrong? P.S.: Old-style declaration works fine.
'setting'
(a docstring) intoprint 'setting'
(a simple debugging statement). While it's certainly plausible that the print statement was intended, there's no harm or error in the docstring, and it doesn't affect the question at all. – Twenty