diff Doc/tutorial/inputoutput.rst @ 83397:6a4746b0afaf 2.7

#13510: clarify that f.readlines() is note necessary to iterate over a file. Patch by Dan Riti.
author Ezio Melotti <ezio.melotti@gmail.com>
date Mon, 15 Apr 2013 19:08:31 +0300
parents 488957f9b664
children ef037ad304c1
line wrap: on
line diff
--- a/Doc/tutorial/inputoutput.rst	Mon Apr 15 09:51:54 2013 -0400
+++ b/Doc/tutorial/inputoutput.rst	Mon Apr 15 19:08:31 2013 +0300
@@ -295,18 +295,8 @@
    >>> f.readline()
    ''
 
-``f.readlines()`` returns a list containing all the lines of data in the file.
-If given an optional parameter *sizehint*, it reads that many bytes from the
-file and enough more to complete a line, and returns the lines from that.  This
-is often used to allow efficient reading of a large file by lines, but without
-having to load the entire file in memory.  Only complete lines will be returned.
-::
-
-   >>> f.readlines()
-   ['This is the first line of the file.\n', 'Second line of the file\n']
-
-An alternative approach to reading lines is to loop over the file object. This is
-memory efficient, fast, and leads to simpler code::
+For reading lines from a file, you can loop over the file object. This is memory
+efficient, fast, and leads to simple code::
 
    >>> for line in f:
            print line,
@@ -314,9 +304,8 @@
    This is the first line of the file.
    Second line of the file
 
-The alternative approach is simpler but does not provide as fine-grained
-control.  Since the two approaches manage line buffering differently, they
-should not be mixed.
+If you want to read all the lines of a file in a list you can also use
+``list(f)`` or ``f.readlines()``.
 
 ``f.write(string)`` writes the contents of *string* to the file, returning
 ``None``.   ::