Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
2ac747c0
Commit
2ac747c0
authored
May 11, 2008
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#2812: document property.getter/setter/deleter.
parent
9510e4a9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
6 deletions
+42
-6
Doc/library/functions.rst
Doc/library/functions.rst
+42
-6
No files found.
Doc/library/functions.rst
View file @
2ac747c0
...
...
@@ -874,10 +874,15 @@ available. They are listed here in alphabetical order.
use
is
to
define
a
managed
attribute
x
::
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
__init__
(
self
):
self
.
_x
=
None
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."
)
If
given
,
*
doc
*
will
be
the
docstring
of
the
property
attribute
.
Otherwise
,
the
...
...
@@ -893,14 +898,45 @@ available. They are listed here in alphabetical order.
"""Get the current voltage."""
return self._voltage
turns the :meth:`voltage` method into a "getter" for a read-only attribute with
the same name.
turns the :meth:`voltage` method into a "getter" for a read-only attribute
with the same name.
A property object has :attr:`getter`, :attr:`setter`, and :attr:`deleter`
methods usable as decorators that create a copy of the property with the
corresponding accessor function set to the decorated function. This is
best explained with an example::
class C(object):
def __init__(self): self._x = None
@property
def x(self):
"""I'
m
the
'x'
property
.
"""
return self._x
@x.setter
def x(self, value):
self._x = value
@x.deleter
def x(self):
del self._x
This code is exactly equivalent to the first example. Be sure to give the
additional functions the same name as the original property (``x`` in this
case.)
The returned property also has the attributes ``fget``, ``fset``, and
``fdel`` corresponding to the constructor arguments.
.. versionadded:: 2.2
.. versionchanged:: 2.5
Use *fget*'s docstring if no *doc* given.
.. versionchanged:: 2.6
The ``getter``, ``setter``, and ``deleter`` attributes were added.
.. function:: range([start,] stop[, step])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment