diff options
author | Raymond Hettinger <python@rcn.com> | 2007-12-18 00:13:45 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2007-12-18 00:13:45 (GMT) |
commit | 88880b2dd6677575586b8c0f5aaffd18f260afa7 (patch) | |
tree | c0126ceb66fad49a1652ac170f3676192b2be00d /Doc | |
parent | e64acfad3dd13809943eecf50f11c40c510dedbe (diff) | |
download | cpython-88880b2dd6677575586b8c0f5aaffd18f260afa7.zip cpython-88880b2dd6677575586b8c0f5aaffd18f260afa7.tar.gz cpython-88880b2dd6677575586b8c0f5aaffd18f260afa7.tar.bz2 |
Add more namedtuple() test cases. Neaten the code and comments.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/collections.rst | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index 771310d..75aa55e 100644 --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -388,8 +388,6 @@ Example:: __slots__ = () - _fields = ('x', 'y') - def __new__(cls, x, y): return tuple.__new__(cls, (x, y)) @@ -404,11 +402,15 @@ Example:: 'Return a new Point object replacing specified fields with new values' return Point(*map(kwds.get, ('x', 'y'), self)) + @property + def _fields(self): + return ('x', 'y') + x = property(itemgetter(0)) y = property(itemgetter(1)) >>> p = Point(11, y=22) # instantiate with positional or keyword arguments - >>> p[0] + p[1] # indexable like the regular tuple (11, 22) + >>> p[0] + p[1] # indexable like the plain tuple (11, 22) 33 >>> x, y = p # unpack like a regular tuple >>> x, y |