summaryrefslogtreecommitdiffstats
path: root/Doc/library/functions.rst
diff options
context:
space:
mode:
authorChris Rands <c_rands100@hotmail.com>2018-12-24 05:07:17 (GMT)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>2018-12-24 05:07:17 (GMT)
commitd378b1f8ed7919f65a89f026bc899204be3773d4 (patch)
tree5e5e4c62c38cb94988cd48727062aa52c8119bec /Doc/library/functions.rst
parent8874f511e7473b08d6b0ccd9261dd415a072a34d (diff)
downloadcpython-d378b1f8ed7919f65a89f026bc899204be3773d4.zip
cpython-d378b1f8ed7919f65a89f026bc899204be3773d4.tar.gz
cpython-d378b1f8ed7919f65a89f026bc899204be3773d4.tar.bz2
bpo-34764: improve docs example of iter() with sentinel value (GH-11222)
Diffstat (limited to 'Doc/library/functions.rst')
-rw-r--r--Doc/library/functions.rst15
1 files changed, 8 insertions, 7 deletions
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index 24a158f..b49d752 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -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)