Commit f0886444 authored by Raymond Hettinger's avatar Raymond Hettinger

Clarify how to add a field to a named tuple.

parent da6aa78c
......@@ -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::
......
......@@ -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())
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment