Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2b06558

Browse files
committed
#26001: merge with 3.5.
2 parents 997e6c1 + 397bb24 commit 2b06558

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

Doc/tutorial/inputoutput.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

273273
To 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.
278279
If the end of the file has been reached, ``f.read()`` will return an empty
279280
string (``''``). ::
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

Comments
 (0)