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

Skip to content

Commit e4b1a18

Browse files
committed
Issue #15624: clarify newline documentation for open and io.TextIOWrapper
Thanks to Chris Jerdonek
2 parents b2d8502 + ecd78fe commit e4b1a18

2 files changed

Lines changed: 30 additions & 24 deletions

File tree

Doc/library/functions.rst

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -878,18 +878,21 @@ are always available. They are listed here in alphabetical order.
878878
mode). It can be ``None``, ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It
879879
works as follows:
880880

881-
* On input, if *newline* is ``None``, universal newlines mode is enabled.
882-
Lines in the input can end in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these
883-
are translated into ``'\n'`` before being returned to the caller. If it is
884-
``''``, universal newline mode is enabled, but line endings are returned to
885-
the caller untranslated. If it has any of the other legal values, input
886-
lines are only terminated by the given string, and the line ending is
887-
returned to the caller untranslated.
888-
889-
* On output, if *newline* is ``None``, any ``'\n'`` characters written are
890-
translated to the system default line separator, :data:`os.linesep`. If
891-
*newline* is ``''`` or ``'\n'``, no translation takes place. If *newline*
892-
is any of the other legal values, any ``'\n'`` characters written are
881+
* When reading input from the stream, if *newline* is ``None``,
882+
universal newlines mode is enabled. Lines in the input can end
883+
in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these are translated
884+
into ``'\n'`` before being returned to the caller. If it is
885+
``''``, universal newline mode is enabled, but line endings are
886+
returned to the caller untranslated. If it has any of the other
887+
legal values, input lines are only terminated by the given
888+
string, and the line ending is returned to the caller
889+
untranslated.
890+
891+
* When writing output to the stream, if *newline* is ``None``, any
892+
``'\n'`` characters written are translated to the system default
893+
line separator, :data:`os.linesep`. If *newline* is ``''`` or
894+
``'\n'``, no translation takes place. If *newline* is any of the
895+
other legal values, any ``'\n'`` characters written are
893896
translated to the given string.
894897

895898
If *closefd* is ``False`` and a file descriptor rather than a filename was

Doc/library/io.rst

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -770,18 +770,21 @@ Text I/O
770770
*newline* controls how line endings are handled. It can be ``None``,
771771
``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It works as follows:
772772

773-
* On input, if *newline* is ``None``, universal newlines mode is enabled.
774-
Lines in the input can end in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these
775-
are translated into ``'\n'`` before being returned to the caller. If it is
776-
``''``, universal newline mode is enabled, but line endings are returned to
777-
the caller untranslated. If it has any of the other legal values, input
778-
lines are only terminated by the given string, and the line ending is
779-
returned to the caller untranslated.
780-
781-
* On output, if *newline* is ``None``, any ``'\n'`` characters written are
782-
translated to the system default line separator, :data:`os.linesep`. If
783-
*newline* is ``''`` or ``'\n'``, no translation takes place. If *newline*
784-
is any of the other legal values, any ``'\n'`` characters written are
773+
* When reading input from the stream, if *newline* is ``None``,
774+
universal newlines mode is enabled. Lines in the input can end
775+
in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these are translated
776+
into ``'\n'`` before being returned to the caller. If it is
777+
``''``, universal newline mode is enabled, but line endings are
778+
returned to the caller untranslated. If it has any of the other
779+
legal values, input lines are only terminated by the given
780+
string, and the line ending is returned to the caller
781+
untranslated.
782+
783+
* When writing output to the stream, if *newline* is ``None``, any
784+
``'\n'`` characters written are translated to the system default
785+
line separator, :data:`os.linesep`. If *newline* is ``''`` or
786+
``'\n'``, no translation takes place. If *newline* is any of the
787+
other legal values, any ``'\n'`` characters written are
785788
translated to the given string.
786789

787790
If *line_buffering* is ``True``, :meth:`flush` is implied when a call to

0 commit comments

Comments
 (0)