Kaydet (Commit) 1c63960c authored tarafından Skip Montanaro's avatar Skip Montanaro

Reformat the open function text so it fits within 80 columns in preparation

for a bit of rewriting.  Separating the reformatting from the rewriting
should make it easier for people to review the substantive changes.
üst f1368ef9
...@@ -701,18 +701,20 @@ available. They are listed here in alphabetical order. ...@@ -701,18 +701,20 @@ available. They are listed here in alphabetical order.
:func:`open` instead of invoking the :class:`file` constructor directly. :func:`open` instead of invoking the :class:`file` constructor directly.
The first two arguments are the same as for ``stdio``'s :cfunc:`fopen`: The first two arguments are the same as for ``stdio``'s :cfunc:`fopen`:
*filename* is the file name to be opened, and *mode* is a string indicating how *filename* is the file name to be opened, and *mode* is a string
the file is to be opened. indicating how the file is to be opened.
The most commonly-used values of *mode* are ``'r'`` for reading, ``'w'`` for The most commonly-used values of *mode* are ``'r'`` for reading, ``'w'``
writing (truncating the file if it already exists), and ``'a'`` for appending for writing (truncating the file if it already exists), and ``'a'`` for
(which on *some* Unix systems means that *all* writes append to the end of the appending (which on *some* Unix systems means that *all* writes append to
file regardless of the current seek position). If *mode* is omitted, it the end of the file regardless of the current seek position). If *mode*
defaults to ``'r'``. When opening a binary file, you should append ``'b'`` to is omitted, it defaults to ``'r'``.
the *mode* value to open the file in binary mode, which will improve
portability. (Appending ``'b'`` is useful even on systems that don't treat When opening a binary file, you should append ``'b'`` to the *mode* value
binary and text files differently, where it serves as documentation.) See below to open the file in binary mode, which will improve portability.
for more possible values of *mode*. (Appending ``'b'`` is useful even on systems that don't treat binary and
text files differently, where it serves as documentation.) See below for
more possible values of *mode*.
.. index:: .. index::
single: line-buffered I/O single: line-buffered I/O
...@@ -720,31 +722,33 @@ available. They are listed here in alphabetical order. ...@@ -720,31 +722,33 @@ available. They are listed here in alphabetical order.
single: buffer size, I/O single: buffer size, I/O
single: I/O control; buffering single: I/O control; buffering
The optional *bufsize* argument specifies the file's desired buffer size: 0 The optional *bufsize* argument specifies the file's desired buffer size:
means unbuffered, 1 means line buffered, any other positive value means use a 0 means unbuffered, 1 means line buffered, any other positive value means
buffer of (approximately) that size. A negative *bufsize* means to use the use a buffer of (approximately) that size. A negative *bufsize* means to
system default, which is usually line buffered for tty devices and fully use the system default, which is usually line buffered for tty devices
buffered for other files. If omitted, the system default is used. [#]_ and fully buffered for other files. If omitted, the system default is
used. [#]_
Modes ``'r+'``, ``'w+'`` and ``'a+'`` open the file for updating (note that
``'w+'`` truncates the file). Append ``'b'`` to the mode to open the file in Modes ``'r+'``, ``'w+'`` and ``'a+'`` open the file for updating (note
binary mode, on systems that differentiate between binary and text files; on that ``'w+'`` truncates the file). Append ``'b'`` to the mode to open
systems that don't have this distinction, adding the ``'b'`` has no effect. the file in binary mode, on systems that differentiate between binary and
text files; on systems that don't have this distinction, adding the
In addition to the standard :cfunc:`fopen` values *mode* may be ``'U'`` or ``'b'`` has no effect.
``'rU'``. Python is usually built with universal newline support; supplying
``'U'`` opens the file as a text file, but lines may be terminated by any of the In addition to the standard :cfunc:`fopen` values *mode* may be ``'U'``
following: the Unix end-of-line convention ``'\n'``, the Macintosh convention or ``'rU'``. Python is usually built with universal newline support;
``'\r'``, or the Windows convention ``'\r\n'``. All of these external supplying ``'U'`` opens the file as a text file, but lines may be
representations are seen as ``'\n'`` by the Python program. If Python is built terminated by any of the following: the Unix end-of-line convention
without universal newline support a *mode* with ``'U'`` is the same as normal ``'\n'``, the Macintosh convention ``'\r'``, or the Windows convention
text mode. Note that file objects so opened also have an attribute called ``'\r\n'``. All of these external representations are seen as ``'\n'`` by
:attr:`newlines` which has a value of ``None`` (if no newlines have yet been the Python program. If Python is built without universal newline support
seen), ``'\n'``, ``'\r'``, ``'\r\n'``, or a tuple containing all the newline a *mode* with ``'U'`` is the same as normal text mode. Note that file
types seen. objects so opened also have an attribute called :attr:`newlines` which
has a value of ``None`` (if no newlines have yet been seen), ``'\n'``,
Python enforces that the mode, after stripping ``'U'``, begins with ``'r'``, ``'\r'``, ``'\r\n'``, or a tuple containing all the newline types seen.
``'w'`` or ``'a'``.
Python enforces that the mode, after stripping ``'U'``, begins with
``'r'``, ``'w'`` or ``'a'``.
See also the :mod:`fileinput` module, the :mod:`os` module, and the See also the :mod:`fileinput` module, the :mod:`os` module, and the
:mod:`os.path` module. :mod:`os.path` module.
......
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