]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Doc: fix example for iter() function. (GH-11959)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 21 Feb 2019 07:59:28 +0000 (23:59 -0800)
committerGitHub <noreply@github.com>
Thu, 21 Feb 2019 07:59:28 +0000 (23:59 -0800)
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@yahoo.com>
Doc/library/functions.rst

index abf3e26d9e8d2b7b8e57f16bdeb441765246f71e..b28f28f2142ab3792c4d9882a5e0a0c36b729373 100644 (file)
@@ -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''):
               process_block(block)