Property error
Rob Williscroft
rtw at freenet.co.uk
Fri Dec 15 06:50:03 EST 2006
king kikapu wrote in news:1166181267.949316.197360@
16g2000cwy.googlegroups.com in comp.lang.python:
> I am sure it is something very obvious
Yes, property is *NOT* a decorator, it can only be used as a decorator in
the one case that is mentioned in the docs:
<quote href="http://docs.python.org/lib/built-in-funcs.html#l2h-57">
If given, doc will be the docstring of the property attribute. Otherwise,
the property will copy fget's docstring (if it exists). This makes it
possible to create read-only properties easily using property() as a
decorator:
class Parrot(object):
def __init__(self):
self._voltage = 100000
@property
def voltage(self):
"""Get the current voltage."""
return self._voltage
</quote>
Note the use of "read-only" in the above description and that the
decorated function (voltage) *is* the properties "fget" function.
Rob.
--
http://www.victim-prime.dsl.pipex.com/
More information about the Python-list
mailing list