- 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
This commit is contained in:
parent
348b7c8304
commit
6f42dfce7c
|
@ -781,30 +781,30 @@ class C:
|
||||||
\begin{verbatim}
|
\begin{verbatim}
|
||||||
class C(object):
|
class C(object):
|
||||||
def __init__(self): self.__x = None
|
def __init__(self): self.__x = None
|
||||||
def getx(self): return self.__x
|
def getx(self): return self._x
|
||||||
def setx(self, value): self.__x = value
|
def setx(self, value): self._x = value
|
||||||
def delx(self): del self.__x
|
def delx(self): del self._x
|
||||||
x = property(getx, setx, delx, "I'm the 'x' property.")
|
x = property(getx, setx, delx, "I'm the 'x' property.")
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
|
||||||
If given, \var{doc} will be the docstring of the property attribute.
|
If given, \var{doc} will be the docstring of the property attribute.
|
||||||
Otherwise, the property will copy \var{fget}'s docstring (if it
|
Otherwise, the property will copy \var{fget}'s docstring (if it
|
||||||
exists). This makes it possible to create read-only properties
|
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}
|
\begin{verbatim}
|
||||||
class Parrot(object):
|
class Parrot(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.__voltage = 100000
|
self._voltage = 100000
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def voltage(self):
|
def voltage(self):
|
||||||
"""Get the current voltage."""
|
"""Get the current voltage."""
|
||||||
return self.__voltage
|
return self._voltage
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
|
||||||
turns the \method{voltage} method into a "getter" for a read-only attribute
|
turns the \method{voltage()} method into a ``getter'' for a read-only
|
||||||
with the same name.
|
attribute with the same name.
|
||||||
|
|
||||||
\versionadded{2.2}
|
\versionadded{2.2}
|
||||||
\versionchanged[Use \var{fget}'s docstring if no \var{doc} given]{2.5}
|
\versionchanged[Use \var{fget}'s docstring if no \var{doc} given]{2.5}
|
||||||
|
|
Loading…
Reference in New Issue