diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index b276ab02d9c..1e213fb9cb7 100644 --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -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:: diff --git a/Lib/collections.py b/Lib/collections.py index 47b0397d0b8..267c39f9e43 100644 --- a/Lib/collections.py +++ b/Lib/collections.py @@ -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())