[Python-checkins] r59895 - in python/trunk: Doc/library/collections.rst Lib/collections.py

raymond.hettinger python-checkins at python.org
Thu Jan 10 21:37:12 CET 2008


Author: raymond.hettinger
Date: Thu Jan 10 21:37:12 2008
New Revision: 59895

Modified:
   python/trunk/Doc/library/collections.rst
   python/trunk/Lib/collections.py
Log:
Clarify how to add a field to a named tuple.

Modified: python/trunk/Doc/library/collections.rst
==============================================================================
--- python/trunk/Doc/library/collections.rst	(original)
+++ python/trunk/Doc/library/collections.rst	Thu Jan 10 21:37:12 2008
@@ -538,7 +538,7 @@
 Subclassing is not useful for adding new, stored fields.  Instead, simply
 create a new named tuple type from the :attr:`_fields` attribute::
 
-    >>> Pixel = namedtuple('Pixel', Point._fields + Color._fields)
+    >>> Point3D = namedtuple('Point3D', Point._fields + ('z',))
 
 Default values can be implemented by using :meth:`_replace` to
 customize a prototype instance::

Modified: python/trunk/Lib/collections.py
==============================================================================
--- python/trunk/Lib/collections.py	(original)
+++ python/trunk/Lib/collections.py	Thu Jan 10 21:37:12 2008
@@ -137,6 +137,9 @@
 
     print Point(11, 22)._replace(x=100)
 
+    Point3D = namedtuple('Point3D', Point._fields + ('z',))
+    print Point3D.__doc__
+
     import doctest
     TestResults = namedtuple('TestResults', 'failed attempted')
     print TestResults(*doctest.testmod())


More information about the Python-checkins mailing list