diff options
author | Fred Drake <fdrake@acm.org> | 2006-06-30 19:29:25 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2006-06-30 19:29:25 (GMT) |
commit | 6f42dfce7cb96b4284bde4ecc08314cbb2738bef (patch) | |
tree | 26b3016fa56df7213b3eed32cde7906f2168ce42 | |
parent | 348b7c8304b29d5cef5e1cf9530c509d663ec433 (diff) | |
download | cpython-6f42dfce7cb96b4284bde4ecc08314cbb2738bef.zip cpython-6f42dfce7cb96b4284bde4ecc08314cbb2738bef.tar.gz cpython-6f42dfce7cb96b4284bde4ecc08314cbb2738bef.tar.bz2 |
- consistency nit: always include "()" in \function and \method
(*should* be done by the presentation, but that requires changes all over)
- avoid spreading the __name meme
-rw-r--r-- | Doc/lib/libfuncs.tex | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/Doc/lib/libfuncs.tex b/Doc/lib/libfuncs.tex index 54b2595..860321d 100644 --- a/Doc/lib/libfuncs.tex +++ b/Doc/lib/libfuncs.tex @@ -781,30 +781,30 @@ class C: \begin{verbatim} class C(object): def __init__(self): self.__x = None - def getx(self): return self.__x - def setx(self, value): self.__x = value - def delx(self): del self.__x + def getx(self): return self._x + def setx(self, value): self._x = value + def delx(self): del self._x x = property(getx, setx, delx, "I'm the 'x' property.") \end{verbatim} If given, \var{doc} will be the docstring of the property attribute. Otherwise, the property will copy \var{fget}'s docstring (if it exists). This makes it possible to create read-only properties - easily using \function{property} as a decorator: + easily using \function{property()} as a decorator: \begin{verbatim} class Parrot(object): def __init__(self): - self.__voltage = 100000 + self._voltage = 100000 @property def voltage(self): """Get the current voltage.""" - return self.__voltage + return self._voltage \end{verbatim} - turns the \method{voltage} method into a "getter" for a read-only attribute - with the same name. + 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} |