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
92985ac6
Commit
92985ac6
authored
Jun 11, 2012
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix indentation of method and attribute examples.
parent
f3d43049
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
19 deletions
+17
-19
Doc/library/collections.rst
Doc/library/collections.rst
+17
-19
No files found.
Doc/library/collections.rst
View file @
92985ac6
...
...
@@ -798,11 +798,11 @@ field names, the method and attribute names start with an underscore.
Class method that makes a new instance from an existing sequence or iterable.
.. doctest::
.. doctest::
>>> t = [11, 22]
>>> Point._make(t)
Point(x=11, y=22)
>>> t = [11, 22]
>>> Point._make(t)
Point(x=11, y=22)
.. method:: somenamedtuple._asdict()
...
...
@@ -819,16 +819,14 @@ field names, the method and attribute names start with an underscore.
.. method:: somenamedtuple._replace(kwargs)
Return a new instance of the named tuple replacing specified fields with new
values:
values:
:
::
>>> p = Point(x=11, y=22)
>>> p._replace(x=33)
Point(x=33, y=22)
>>> p = Point(x=11, y=22)
>>> p._replace(x=33)
Point(x=33, y=22)
>>> for partnum, record in inventory.items():
... inventory[partnum] = record._replace(price=newprices[partnum], timestamp=time.now())
>>> for partnum, record in inventory.items():
... inventory[partnum] = record._replace(price=newprices[partnum], timestamp=time.now())
.. attribute:: somenamedtuple._source
...
...
@@ -844,15 +842,15 @@ field names, the method and attribute names start with an underscore.
Tuple of strings listing the field names. Useful for introspection
and for creating new named tuple types from existing named tuples.
.. doctest::
.. doctest::
>>> p._fields # view the field names
('x', 'y')
>>> p._fields # view the field names
('x', 'y')
>>> Color = namedtuple('Color', 'red green blue')
>>> Pixel = namedtuple('Pixel', Point._fields + Color._fields)
>>> Pixel(11, 22, 128, 255, 0)
Pixel(x=11, y=22, red=128, green=255, blue=0)
>>> Color = namedtuple('Color', 'red green blue')
>>> Pixel = namedtuple('Pixel', Point._fields + Color._fields)
>>> Pixel(11, 22, 128, 255, 0)
Pixel(x=11, y=22, red=128, green=255, blue=0)
To retrieve a field whose name is stored in a string, use the :func:`getattr`
function:
...
...
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