]> granicus.if.org Git - python/commitdiff
Doc: fix example for iter() function. (GH-11959)
authorCristian Ciupitu <cristian.ciupitu@yahoo.com>
Thu, 21 Feb 2019 07:53:06 +0000 (09:53 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 21 Feb 2019 07:53:06 +0000 (09:53 +0200)
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.

Doc/library/functions.rst

index cca28ff5fb3b66318d79671fd6456c4456981f78..ebbee71f48eda7931517c4fc5995b74a28fcc606 100644 (file)
@@ -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)