Gregor Horvath a écrit :
Hi,
why is this code failing?
class B(object):
pass
B.testattr = property(lambda s:"hallo")
b = B()
b.testattr = "test"
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
/tmp/python-14202ViU.py in <module>()
14 B.testattr = property(lambda s:"hallo")
15 b = B()
---> 16 b.testattr = "test"
17
18
<type 'exceptions.AttributeError'>: can't set attribute
It's not failing, it's doing exactly what's expected. You made testattr
a read-only property by not providing a setter.
--
http://mail.python.org/mailman/listinfo/python-list