Overwriting property-> can't set attribute
norseman
norseman at hughes.net
Fri Aug 22 13:31:27 EDT 2008
Gregor Horvath wrote:
> 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
>
> --
> Greg
> --
> http://mail.python.org/mailman/listinfo/python-list
>
====================================
b = B() # synonyms
When B.testattr = "hallo" so does b.testattr
So if in subsequent code:
B.testattr = property(lambda s:"test")
Then:
b.testattr yields "test"
unless b was essentially destroyed/reused in between times
this is how/why things like:
gc = damn-lot-of-typing-due-to-long-names
gc.something
works as if it was:
damn-lot-of-typing-due-to-long-names.something
Steve
norseman at hughes.net
More information about the Python-list
mailing list