From: Cristian Ciupitu Date: Thu, 21 Feb 2019 07:53:06 +0000 (+0200) Subject: Doc: fix example for iter() function. (GH-11959) X-Git-Tag: v3.8.0a2~30 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=11fa0e48a958716186eb99348a46064e944eccf6;p=thirdparty%2FPython%2Fcpython.git 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. --- diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index cca28ff5fb3b..ebbee71f48ed 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -816,7 +816,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)