[Python-checkins] Doc: fix example for iter() function. (GH-11959)

Miss Islington (bot) webhook-mailer at python.org
Thu Feb 21 02:59:35 EST 2019

commit: 92ac01b104b80f9251fcb17ab4cc1845c1f91ac2
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-02-20T23:59:28-08:00

Doc: fix example for iter() function. (GH-11959)

read() returns bytes for a file opened in binary mode,
so b'' should be used as a sentinel instead of ''.
Otherwise the loop will be infinite.
(cherry picked from commit 11fa0e48a958716186eb99348a46064e944eccf6)

Co-authored-by: Cristian Ciupitu <cristian.ciupitu at yahoo.com>

M Doc/library/functions.rst

diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index abf3e26d9e8d..b28f28f2142a 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -815,7 +815,7 @@ are always available.  They are listed here in alphabetical order.
       from functools import partial
       with open('mydata.db', 'rb') as f:
-          for block in iter(partial(f.read, 64), ''):
+          for block in iter(partial(f.read, 64), b''):

More information about the Python-checkins mailing list