@@ -271,10 +271,11 @@ The rest of the examples in this section will assume that a file object called
271271``f `` has already been created.
272272
273273To read a file's contents, call ``f.read(size) ``, which reads some quantity of
274- data and returns it as a string or bytes object. *size * is an optional numeric
275- argument. When *size * is omitted or negative, the entire contents of the file
276- will be read and returned; it's your problem if the file is twice as large as
277- your machine's memory. Otherwise, at most *size * bytes are read and returned.
274+ data and returns it as a string (in text mode) or bytes object (in binary mode).
275+ *size * is an optional numeric argument. When *size * is omitted or negative, the
276+ entire contents of the file will be read and returned; it's your problem if the
277+ file is twice as large as your machine's memory. Otherwise, at most *size * bytes
278+ are read and returned.
278279If the end of the file has been reached, ``f.read() `` will return an empty
279280string (``'' ``). ::
280281
@@ -315,11 +316,11 @@ the number of characters written. ::
315316 >>> f.write('This is a test\n')
316317 15
317318
318- To write something other than a string, it needs to be converted to a string
319- first ::
319+ Other types of objects need to be converted -- either to a string (in text mode)
320+ or a bytes object (in binary mode) -- before writing them ::
320321
321322 >>> value = ('the answer', 42)
322- >>> s = str(value)
323+ >>> s = str(value) # convert the tuple to string
323324 >>> f.write(s)
324325 18
325326
0 commit comments