@@ -701,50 +701,54 @@ available. They are listed here in alphabetical order.
701
701
:func: `open ` instead of invoking the :class: `file ` constructor directly.
702
702
703
703
The first two arguments are the same as for ``stdio ``'s :cfunc: `fopen `:
704
- *filename * is the file name to be opened, and *mode * is a string indicating how
705
- the file is to be opened.
706
-
707
- The most commonly-used values of *mode * are ``'r' `` for reading, ``'w' `` for
708
- writing (truncating the file if it already exists), and ``'a' `` for appending
709
- (which on *some * Unix systems means that *all * writes append to the end of the
710
- file regardless of the current seek position). If *mode * is omitted, it
711
- defaults to ``'r' ``. When opening a binary file, you should append ``'b' `` to
712
- the *mode * value to open the file in binary mode, which will improve
713
- portability. (Appending ``'b' `` is useful even on systems that don't treat
714
- binary and text files differently, where it serves as documentation.) See below
715
- for more possible values of *mode *.
704
+ *filename * is the file name to be opened, and *mode * is a string
705
+ indicating how the file is to be opened.
706
+
707
+ The most commonly-used values of *mode * are ``'r' `` for reading, ``'w' ``
708
+ for writing (truncating the file if it already exists), and ``'a' `` for
709
+ appending (which on *some * Unix systems means that *all * writes append to
710
+ the end of the file regardless of the current seek position). If *mode *
711
+ is omitted, it defaults to ``'r' ``.
712
+
713
+ When opening a binary file, you should append ``'b' `` to the *mode * value
714
+ to open the file in binary mode, which will improve portability.
715
+ (Appending ``'b' `` is useful even on systems that don't treat binary and
716
+ text files differently, where it serves as documentation.) See below for
717
+ more possible values of *mode *.
716
718
717
719
.. index ::
718
720
single: line-buffered I/O
719
721
single: unbuffered I/O
720
722
single: buffer size, I/O
721
723
single: I/O control; buffering
722
724
723
- The optional *bufsize * argument specifies the file's desired buffer size: 0
724
- means unbuffered, 1 means line buffered, any other positive value means use a
725
- buffer of (approximately) that size. A negative *bufsize * means to use the
726
- system default, which is usually line buffered for tty devices and fully
727
- buffered for other files. If omitted, the system default is used. [# ]_
728
-
729
- Modes ``'r+' ``, ``'w+' `` and ``'a+' `` open the file for updating (note that
730
- ``'w+' `` truncates the file). Append ``'b' `` to the mode to open the file in
731
- binary mode, on systems that differentiate between binary and text files; on
732
- systems that don't have this distinction, adding the ``'b' `` has no effect.
733
-
734
- In addition to the standard :cfunc: `fopen ` values *mode * may be ``'U' `` or
735
- ``'rU' ``. Python is usually built with universal newline support; supplying
736
- ``'U' `` opens the file as a text file, but lines may be terminated by any of the
737
- following: the Unix end-of-line convention ``'\n' ``, the Macintosh convention
738
- ``'\r' ``, or the Windows convention ``'\r\n' ``. All of these external
739
- representations are seen as ``'\n' `` by the Python program. If Python is built
740
- without universal newline support a *mode * with ``'U' `` is the same as normal
741
- text mode. Note that file objects so opened also have an attribute called
742
- :attr: `newlines ` which has a value of ``None `` (if no newlines have yet been
743
- seen), ``'\n' ``, ``'\r' ``, ``'\r\n' ``, or a tuple containing all the newline
744
- types seen.
745
-
746
- Python enforces that the mode, after stripping ``'U' ``, begins with ``'r' ``,
747
- ``'w' `` or ``'a' ``.
725
+ The optional *bufsize * argument specifies the file's desired buffer size:
726
+ 0 means unbuffered, 1 means line buffered, any other positive value means
727
+ use a buffer of (approximately) that size. A negative *bufsize * means to
728
+ use the system default, which is usually line buffered for tty devices
729
+ and fully buffered for other files. If omitted, the system default is
730
+ used. [# ]_
731
+
732
+ Modes ``'r+' ``, ``'w+' `` and ``'a+' `` open the file for updating (note
733
+ that ``'w+' `` truncates the file). Append ``'b' `` to the mode to open
734
+ the file in binary mode, on systems that differentiate between binary and
735
+ text files; on systems that don't have this distinction, adding the
736
+ ``'b' `` has no effect.
737
+
738
+ In addition to the standard :cfunc: `fopen ` values *mode * may be ``'U' ``
739
+ or ``'rU' ``. Python is usually built with universal newline support;
740
+ supplying ``'U' `` opens the file as a text file, but lines may be
741
+ terminated by any of the following: the Unix end-of-line convention
742
+ ``'\n' ``, the Macintosh convention ``'\r' ``, or the Windows convention
743
+ ``'\r\n' ``. All of these external representations are seen as ``'\n' `` by
744
+ the Python program. If Python is built without universal newline support
745
+ a *mode * with ``'U' `` is the same as normal text mode. Note that file
746
+ objects so opened also have an attribute called :attr: `newlines ` which
747
+ has a value of ``None `` (if no newlines have yet been seen), ``'\n' ``,
748
+ ``'\r' ``, ``'\r\n' ``, or a tuple containing all the newline types seen.
749
+
750
+ Python enforces that the mode, after stripping ``'U' ``, begins with
751
+ ``'r' ``, ``'w' `` or ``'a' ``.
748
752
749
753
See also the :mod: `fileinput ` module, the :mod: `os ` module, and the
750
754
:mod: `os.path ` module.
0 commit comments