Kaydet (Commit) 8cad9c77 authored tarafından Benjamin Peterson's avatar Benjamin Peterson

fix docs about open's return value #5539

(how annoying to have the same docs in two places)

(three if you count the docstring...)
üst 21e5fcd2
...@@ -749,9 +749,22 @@ are always available. They are listed here in alphabetical order. ...@@ -749,9 +749,22 @@ are always available. They are listed here in alphabetical order.
the other legal values, any ``'\n'`` characters written are translated to the other legal values, any ``'\n'`` characters written are translated to
the given string. the given string.
If *closefd* is ``False``, the underlying file descriptor will be kept open If *closefd* is ``False`` and a file descriptor rather than a filename was
when the file is closed. This does not work when a file name is given and given, the underlying file descriptor will be kept open when the file is
must be ``True`` in that case. closed. If a filename is given *closefd* has no effect and must be ``True``
(the default).
The type of file object returned by the :func:`open` function depends on the
mode. When :func:`open` is used to open a file in a text mode (``'w'``,
``'r'``, ``'wt'``, ``'rt'``, etc.), it returns a subclass of
:class:`io.TextIOBase` (specifically :class:`io.TextIOWrapper`). When used
to open a file in a binary mode with buffering, the returned class is a
subclass of :class:`io.BufferedIOBase`. The exact class varies: in read
binary mode, it returns a :class:`io.BufferedReader`; in write binary and
append binary modes, it returns a :class:`io.BufferedWriter`, and in
read/write mode, it returns a :class:`io.BufferedRandom`. When buffering is
disabled, the raw stream, a subclass of :class:`io.RawIOBase`,
:class:`io.FileIO`, is returned.
.. index:: .. index::
single: line-buffered I/O single: line-buffered I/O
...@@ -763,8 +776,8 @@ are always available. They are listed here in alphabetical order. ...@@ -763,8 +776,8 @@ are always available. They are listed here in alphabetical order.
module: sys module: sys
See also the file handling modules, such as, :mod:`fileinput`, :mod:`io` See also the file handling modules, such as, :mod:`fileinput`, :mod:`io`
(where :func:`open()` is declared), :mod:`os`, :mod:`os.path`, (where :func:`open` is declared), :mod:`os`, :mod:`os.path`, :mod:`tempfile`,
:mod:`tempfile`, and :mod:`shutil`. and :mod:`shutil`.
.. XXX works for bytes too, but should it? .. XXX works for bytes too, but should it?
......
...@@ -134,19 +134,21 @@ Module Interface ...@@ -134,19 +134,21 @@ Module Interface
the other legal values, any ``'\n'`` characters written are translated to the other legal values, any ``'\n'`` characters written are translated to
the given string. the given string.
If *closefd* is ``False`` and a file descriptor rather than a If *closefd* is ``False`` and a file descriptor rather than a filename was
filename was given, the underlying file descriptor will be kept open given, the underlying file descriptor will be kept open when the file is
when the file is closed. If a filename is given *closefd* has no closed. If a filename is given *closefd* has no effect and must be ``True``
effect but must be ``True`` (the default). (the default).
The type of file object returned by the :func:`open` function depends The type of file object returned by the :func:`open` function depends on the
on the mode. When :func:`open` is used to open a file in a text mode mode. When :func:`open` is used to open a file in a text mode (``'w'``,
(``'w'``, ``'r'``, ``'wt'``, ``'rt'``, etc.), it returns a ``'r'``, ``'wt'``, ``'rt'``, etc.), it returns a subclass of
:class:`TextIOWrapper`. When used to open a file in a binary mode, :class:`TextIOBase` (specifically :class:`TextIOWrapper`). When used to open
the returned class varies: in read binary mode, it returns a a file in a binary mode with buffering, the returned class is a subclass of
:class:`BufferedReader`; in write binary and append binary modes, it :class:`BufferedIOBase`. The exact class varies: in read binary mode, it
returns a :class:`BufferedWriter`, and in read/write mode, it returns returns a :class:`BufferedReader`; in write binary and append binary modes,
a :class:`BufferedRandom`. it returns a :class:`BufferedWriter`, and in read/write mode, it returns a
:class:`BufferedRandom`. When buffering is disabled, the raw stream, a
subclass of :class:`RawIOBase`, :class:`FileIO`, is returned.
It is also possible to use a string or bytearray as a file for both reading It is also possible to use a string or bytearray as a file for both reading
and writing. For strings :class:`StringIO` can be used like a file opened in and writing. For strings :class:`StringIO` can be used like a file opened in
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment