diff options
author | Georg Brandl <georg@python.org> | 2010-08-02 19:23:34 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2010-08-02 19:23:34 (GMT) |
commit | 7528b9b8acb3c593aa36b25a26476b5588139e26 (patch) | |
tree | 43b88c1922ea71ea6ca11c5436e6eab6c086d773 /Doc | |
parent | 353ebce2a02c1ee74f55524f9330eb54c1c6b2c7 (diff) | |
download | cpython-7528b9b8acb3c593aa36b25a26476b5588139e26.zip cpython-7528b9b8acb3c593aa36b25a26476b5588139e26.tar.gz cpython-7528b9b8acb3c593aa36b25a26476b5588139e26.tar.bz2 |
#8172: how does one use a property?
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/functions.rst | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 5c21f34..5fb4f70 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -847,7 +847,7 @@ are always available. They are listed here in alphabetical order. *fget* is a function for getting an attribute value, likewise *fset* is a function for setting, and *fdel* a function for del'ing, an attribute. Typical - use is to define a managed attribute x:: + use is to define a managed attribute ``x``:: class C(object): def __init__(self): @@ -861,6 +861,9 @@ are always available. They are listed here in alphabetical order. del self._x x = property(getx, setx, delx, "I'm the 'x' property.") + If then *c* is an instance of *C*, ``c.x`` will invoke the getter, + ``c.x = value`` will invoke the setter and ``del c.x`` the deleter. + 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 :func:`property` as a :term:`decorator`:: |