]> granicus.if.org Git - python/commitdiff
Clarify how to add a field to a named tuple.
authorRaymond Hettinger <python@rcn.com>
Thu, 10 Jan 2008 20:37:12 +0000 (20:37 +0000)
committerRaymond Hettinger <python@rcn.com>
Thu, 10 Jan 2008 20:37:12 +0000 (20:37 +0000)
Doc/library/collections.rst
Lib/collections.py

index b276ab02d9ce931aab7a1ce6f61e77de9e7971e3..1e213fb9cb750fd854df10da4bfa4ed9018b1d9a 100644 (file)
@@ -538,7 +538,7 @@ faster versions that bypass error-checking and that localize variable access::
 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::
index 47b0397d0b89cc52e0a107d9948b2ccae8f4e1df..267c39f9e43d0aef29210afbcd2a2eaadcc1b7a7 100644 (file)
@@ -137,6 +137,9 @@ if __name__ == '__main__':
 
     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())