Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
1ea0ae74
Commit
1ea0ae74
authored
Jan 08, 2008
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Docs on named tuple's naming conventions and limits of subclassing
parent
0ce3fda7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
1 deletion
+7
-1
Doc/library/collections.rst
Doc/library/collections.rst
+7
-1
No files found.
Doc/library/collections.rst
View file @
1ea0ae74
...
...
@@ -446,7 +446,8 @@ by the :mod:`csv` or :mod:`sqlite3` modules::
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 @@ faster versions that bypass error-checking and that localize variable access::
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::
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment