Skip to content

Commit 0a5f4a2

Browse files
committed
Expand file objects in datamodel to include methods
1 parent 2ff7393 commit 0a5f4a2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Doc/reference/datamodel.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,12 +1385,28 @@ also :func:`os.popen`, :func:`os.fdopen`, and the
13851385
:meth:`~socket.socket.makefile` method of socket objects (and perhaps by
13861386
other functions or methods provided by extension modules).
13871387

1388+
File objects implement common methods, listed below, to simplify usage in
1389+
generic code. They are expected to be :ref:`context-managers`.
1390+
13881391
The objects ``sys.stdin``, ``sys.stdout`` and ``sys.stderr`` are
13891392
initialized to file objects corresponding to the interpreter's standard
13901393
input, output and error streams; they are all open in text mode and
13911394
therefore follow the interface defined by the :class:`io.TextIOBase`
13921395
abstract class.
13931396

1397+
.. method:: file.read(size=-1, /)
1398+
1399+
Retrieve up to *size* data from the file. As a convenience if *size* is
1400+
unspecified or -1 retrieve all data available.
1401+
1402+
.. method:: file.write(data, /)
1403+
1404+
Store *data* to the file.
1405+
1406+
.. method:: file.close()
1407+
1408+
Flush any buffers and close the underlying file.
1409+
13941410

13951411
Internal types
13961412
--------------

0 commit comments

Comments
 (0)