summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2006-06-30 18:47:56 (GMT)
committerGeorg Brandl <georg@python.org>2006-06-30 18:47:56 (GMT)
commit348b7c8304b29d5cef5e1cf9530c509d663ec433 (patch)
tree0523772caa92981e131c992bc9523f63e0ba30ce
parent08612926a1fa4e8fd88c4f3b227ab8155e575124 (diff)
downloadcpython-348b7c8304b29d5cef5e1cf9530c509d663ec433.zip
cpython-348b7c8304b29d5cef5e1cf9530c509d663ec433.tar.gz
cpython-348b7c8304b29d5cef5e1cf9530c509d663ec433.tar.bz2
Document decorator usage of property.
-rw-r--r--Doc/lib/libfuncs.tex17
1 files changed, 16 insertions, 1 deletions
diff --git a/Doc/lib/libfuncs.tex b/Doc/lib/libfuncs.tex
index 7cfdfbb..54b2595 100644
--- a/Doc/lib/libfuncs.tex
+++ b/Doc/lib/libfuncs.tex
@@ -789,7 +789,22 @@ class C(object):
If given, \var{doc} will be the docstring of the property attribute.
Otherwise, the property will copy \var{fget}'s docstring (if it
- exists).
+ exists). This makes it possible to create read-only properties
+ easily using \function{property} as a decorator:
+
+\begin{verbatim}
+class Parrot(object):
+ def __init__(self):
+ self.__voltage = 100000
+
+ @property
+ def voltage(self):
+ """Get the current voltage."""
+ return self.__voltage
+\end{verbatim}
+
+ turns the \method{voltage} method into a "getter" for a read-only attribute
+ with the same name.
\versionadded{2.2}
\versionchanged[Use \var{fget}'s docstring if no \var{doc} given]{2.5}