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
d378b1f8
Commit
d378b1f8
authored
Dec 24, 2018
by
Chris Rands
Committed by
Raymond Hettinger
Dec 23, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-34764: improve docs example of iter() with sentinel value (GH-11222)
parent
8874f511
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
7 deletions
+9
-7
Doc/library/functions.rst
Doc/library/functions.rst
+8
-7
Misc/NEWS.d/next/Documentation/2018-12-23-23-52-31.bpo-34764.DwOGeT.rst
...xt/Documentation/2018-12-23-23-52-31.bpo-34764.DwOGeT.rst
+1
-0
No files found.
Doc/library/functions.rst
View file @
d378b1f8
...
...
@@ -810,13 +810,14 @@ are always available. They are listed here in alphabetical order.
See also :ref:`typeiter`.
One useful application of the second form of :func:`iter` is to read lines of
a file until a certain line is reached. The following example reads a file
until the :meth:`~io.TextIOBase.readline` method returns an empty string::
with open('mydata.txt') as fp:
for line in iter(fp.readline, ''):
process_line(line)
One useful application of the second form of :func:`iter` is to build a
block-reader. For example, reading fixed-width blocks from a binary
database file until the end of file is reached::
from functools import partial
with open('mydata.db', 'rb') as f:
for block in iter(partial(f.read, 64), ''):
process_block(block)
.. function:: len(s)
...
...
Misc/NEWS.d/next/Documentation/2018-12-23-23-52-31.bpo-34764.DwOGeT.rst
0 → 100644
View file @
d378b1f8
Improve example of iter() with 2nd sentinel argument.
\ No newline at end of file
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