summaryrefslogtreecommitdiffstats
path: root/Doc/tutorial
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2013-04-15 16:09:29 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2013-04-15 16:09:29 (GMT)
commitacfc454c10ab2fe5dafd4c90a15eaae8cef214c2 (patch)
tree39d49b9572ea67b8ea2d0ef08ec6513d1f267ac5 /Doc/tutorial
parent7d55a40b9a2c386d1389fab5b3fe48960ced919a (diff)
parented3cd7e445e7be413d1b454471454f7ff9f21f1f (diff)
downloadcpython-acfc454c10ab2fe5dafd4c90a15eaae8cef214c2.zip
cpython-acfc454c10ab2fe5dafd4c90a15eaae8cef214c2.tar.gz
cpython-acfc454c10ab2fe5dafd4c90a15eaae8cef214c2.tar.bz2
#13510: merge with 3.3.
Diffstat (limited to 'Doc/tutorial')
-rw-r--r--Doc/tutorial/inputoutput.rst19
1 files changed, 4 insertions, 15 deletions
diff --git a/Doc/tutorial/inputoutput.rst b/Doc/tutorial/inputoutput.rst
index c804e25..ef22459 100644
--- a/Doc/tutorial/inputoutput.rst
+++ b/Doc/tutorial/inputoutput.rst
@@ -300,18 +300,8 @@ containing only a single newline. ::
>>> 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, end='')
@@ -319,9 +309,8 @@ memory efficient, fast, and leads to simpler code::
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
the number of characters written. ::