summaryrefslogtreecommitdiffstats
path: root/Doc/tutorial
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2016-01-12 09:27:58 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2016-01-12 09:27:58 (GMT)
commit2b06558769e23bd91d7dbb88dbfb6b5ed6e0054a (patch)
tree1d24cffb7b56149fce04bf384dab3b2e17b917d4 /Doc/tutorial
parent997e6c1dd854cc35870525a0d434d9b01b6715d3 (diff)
parent397bb2486a50103ce4bea1cc1f60c78c93dbc56f (diff)
downloadcpython-2b06558769e23bd91d7dbb88dbfb6b5ed6e0054a.zip
cpython-2b06558769e23bd91d7dbb88dbfb6b5ed6e0054a.tar.gz
cpython-2b06558769e23bd91d7dbb88dbfb6b5ed6e0054a.tar.bz2
#26001: merge with 3.5.
Diffstat (limited to 'Doc/tutorial')
-rw-r--r--Doc/tutorial/inputoutput.rst15
1 files changed, 8 insertions, 7 deletions
diff --git a/Doc/tutorial/inputoutput.rst b/Doc/tutorial/inputoutput.rst
index c157f22..5314fed 100644
--- a/Doc/tutorial/inputoutput.rst
+++ b/Doc/tutorial/inputoutput.rst
@@ -271,10 +271,11 @@ The rest of the examples in this section will assume that a file object called
``f`` has already been created.
To read a file's contents, call ``f.read(size)``, which reads some quantity of
-data and returns it as a string or bytes object. *size* is an optional numeric
-argument. When *size* is omitted or negative, the entire contents of the file
-will be read and returned; it's your problem if the file is twice as large as
-your machine's memory. Otherwise, at most *size* bytes are read and returned.
+data and returns it as a string (in text mode) or bytes object (in binary mode).
+*size* is an optional numeric argument. When *size* is omitted or negative, the
+entire contents of the file will be read and returned; it's your problem if the
+file is twice as large as your machine's memory. Otherwise, at most *size* bytes
+are read and returned.
If the end of the file has been reached, ``f.read()`` will return an empty
string (``''``). ::
@@ -315,11 +316,11 @@ the number of characters written. ::
>>> f.write('This is a test\n')
15
-To write something other than a string, it needs to be converted to a string
-first::
+Other types of objects need to be converted -- either to a string (in text mode)
+or a bytes object (in binary mode) -- before writing them::
>>> value = ('the answer', 42)
- >>> s = str(value)
+ >>> s = str(value) # convert the tuple to string
>>> f.write(s)
18