Merged revisions 69466,69480 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r69466 | raymond.hettinger | 2009-02-09 12:39:41 -0600 (Mon, 09 Feb 2009) | 3 lines
Issue 5171: itertools.product docstring missing 'repeat' argument
........
r69480 | raymond.hettinger | 2009-02-09 19:24:05 -0600 (Mon, 09 Feb 2009) | 1 line
Issue 1818: collections.namedtuple() to support automatic renaming of invalid fieldnames.
........
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst
index 32cc639..9ff8a27 100644
--- a/Doc/library/collections.rst
+++ b/Doc/library/collections.rst
@@ -597,7 +597,7 @@
self-documenting code. They can be used wherever regular tuples are used, and
they add the ability to access fields by name instead of position index.
-.. function:: namedtuple(typename, field_names, [verbose])
+.. function:: namedtuple(typename, field_names, [verbose], [rename])
Returns a new tuple subclass named *typename*. The new subclass is used to
create tuple-like objects that have fields accessible by attribute lookup as
@@ -615,11 +615,19 @@
a :mod:`keyword` such as *class*, *for*, *return*, *global*, *pass*,
or *raise*.
+ If *rename* is true, invalid fieldnames are automatically replaced
+ with positional names. For example, ``['abc', 'def', 'ghi', 'abc']`` is
+ converted to ``['abc', '_2', 'ghi', '_4']``, eliminating the keyword
+ ``def`` and the duplicate fieldname ``abc``.
+
If *verbose* is true, the class definition is printed just before being built.
Named tuple instances do not have per-instance dictionaries, so they are
lightweight and require no more memory than regular tuples.
+ .. versionchanged:: 2.7
+ added support for *rename*.
+
Example:
.. doctest::