Overwriting property-> can't set attribute

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Fri Aug 22 05:03:33 EDT 2008


Raymond Hettinger a écrit :
> On Aug 22, 5:38 am, Gregor Horvath <g... at gregor-horvath.com> wrote:
>> why is this code failing?
>>
>> class B(object):
>>      pass
>>
>> B.testattr = property(lambda s:"hallo")
>> b = B()
>> b.testattr = "test"
> 
> First, property() only works when attached to classes, not instances.
> So the assignment should be:  B.testattr = property(...)

Mmm... You may want to reread the OP code more carefully !-)




More information about the Python-list mailing list