diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-02-10 02:41:10 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-02-10 02:41:10 (GMT) |
commit | a86f2c06fd08e8aebf3641c1ad2d234425b90c55 (patch) | |
tree | 0780de78edaaf79a9dbe66d7b2011a8cbb4c9ddd /Doc/library | |
parent | 3a409e91d80b754699c9522217d70abd28d6f4f1 (diff) | |
download | cpython-a86f2c06fd08e8aebf3641c1ad2d234425b90c55.zip cpython-a86f2c06fd08e8aebf3641c1ad2d234425b90c55.tar.gz cpython-a86f2c06fd08e8aebf3641c1ad2d234425b90c55.tar.bz2 |
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.
........
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/collections.rst | 10 |
1 files changed, 9 insertions, 1 deletions
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 @@ Named tuples assign meaning to each position in a tuple and allow for more reada 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 @@ they add the ability to access fields by name instead of position index. 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:: |