[Python-checkins] r59850 - python/trunk/Doc/library/collections.rst

raymond.hettinger python-checkins at python.org
Tue Jan 8 03:24:15 CET 2008


Author: raymond.hettinger
Date: Tue Jan  8 03:24:15 2008
New Revision: 59850

Modified:
   python/trunk/Doc/library/collections.rst
Log:
Docs on named tuple's naming conventions and limits of subclassing

Modified: python/trunk/Doc/library/collections.rst
==============================================================================
--- python/trunk/Doc/library/collections.rst	(original)
+++ python/trunk/Doc/library/collections.rst	Tue Jan  8 03:24:15 2008
@@ -446,7 +446,8 @@
        print emp.name, emp.title
 
 In addition to the methods inherited from tuples, named tuples support
-three additional methods and one attribute.
+three additional methods and one attribute.  To prevent conflicts with
+field names, the method and attribute names start with an underscore.
 
 .. method:: somenamedtuple._make(iterable)
 
@@ -533,6 +534,11 @@
         def _replace(self, _map=map, **kwds):
             return self._make(_map(kwds.get, ('x', 'y'), self))
 
+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)
+
 Default values can be implemented by using :meth:`_replace` to
 customize a prototype instance::
 


More information about the Python-checkins mailing list