mirror of
https://github.com/python/cpython.git
synced 2025-09-18 14:40:43 +00:00
merge
This commit is contained in:
commit
ed16b2e5ab
2 changed files with 14 additions and 7 deletions
|
@ -1106,9 +1106,11 @@ are always available. They are listed here in alphabetical order.
|
||||||
|
|
||||||
Return a property attribute.
|
Return a property attribute.
|
||||||
|
|
||||||
*fget* is a function for getting an attribute value, likewise *fset* is a
|
*fget* is a function for getting an attribute value. *fset* is a function
|
||||||
function for setting, and *fdel* a function for del'ing, an attribute. Typical
|
for setting an attribute value. *fdel* is a function for deleting an attribute
|
||||||
use is to define a managed attribute ``x``::
|
value. And *doc* creates a docstring for the attribute.
|
||||||
|
|
||||||
|
A typical use is to define a managed attribute ``x``::
|
||||||
|
|
||||||
class C:
|
class C:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -1116,13 +1118,16 @@ are always available. They are listed here in alphabetical order.
|
||||||
|
|
||||||
def getx(self):
|
def getx(self):
|
||||||
return self._x
|
return self._x
|
||||||
|
|
||||||
def setx(self, value):
|
def setx(self, value):
|
||||||
self._x = value
|
self._x = value
|
||||||
|
|
||||||
def delx(self):
|
def delx(self):
|
||||||
del self._x
|
del self._x
|
||||||
|
|
||||||
x = property(getx, setx, delx, "I'm the 'x' property.")
|
x = property(getx, setx, delx, "I'm the 'x' property.")
|
||||||
|
|
||||||
If then *c* is an instance of *C*, ``c.x`` will invoke the getter,
|
If *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.
|
``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
|
If given, *doc* will be the docstring of the property attribute. Otherwise, the
|
||||||
|
@ -1138,8 +1143,9 @@ are always available. They are listed here in alphabetical order.
|
||||||
"""Get the current voltage."""
|
"""Get the current voltage."""
|
||||||
return self._voltage
|
return self._voltage
|
||||||
|
|
||||||
turns the :meth:`voltage` method into a "getter" for a read-only attribute
|
The ``@property`` decorator turns the :meth:`voltage` method into a "getter"
|
||||||
with the same name.
|
for a read-only attribute with the same name, and it sets the docstring for
|
||||||
|
*voltage* to "Get the current voltage."
|
||||||
|
|
||||||
A property object has :attr:`~property.getter`, :attr:`~property.setter`,
|
A property object has :attr:`~property.getter`, :attr:`~property.setter`,
|
||||||
and :attr:`~property.deleter` methods usable as decorators that create a
|
and :attr:`~property.deleter` methods usable as decorators that create a
|
||||||
|
@ -1167,7 +1173,7 @@ are always available. They are listed here in alphabetical order.
|
||||||
additional functions the same name as the original property (``x`` in this
|
additional functions the same name as the original property (``x`` in this
|
||||||
case.)
|
case.)
|
||||||
|
|
||||||
The returned property also has the attributes ``fget``, ``fset``, and
|
The returned property object also has the attributes ``fget``, ``fset``, and
|
||||||
``fdel`` corresponding to the constructor arguments.
|
``fdel`` corresponding to the constructor arguments.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -250,6 +250,7 @@ David Cinege
|
||||||
Craig Citro
|
Craig Citro
|
||||||
Gilles Civario
|
Gilles Civario
|
||||||
Chris Clark
|
Chris Clark
|
||||||
|
Diana Clarke
|
||||||
Laurie Clark-Michalek
|
Laurie Clark-Michalek
|
||||||
Mike Clarkson
|
Mike Clarkson
|
||||||
Andrew Clegg
|
Andrew Clegg
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue