From c84dd115115981b3d3f3d5775df5086f3ea53195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Delfino?= Date: Sat, 15 Dec 2018 20:25:43 -0300 Subject: [PATCH 1/3] Improve doc on open's mode + --- Doc/library/functions.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index e7b98eb44b2e21..1dfe4d102388c1 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -1002,13 +1002,13 @@ are always available. They are listed here in alphabetical order. ``'a'`` open for writing, appending to the end of the file if it exists ``'b'`` binary mode ``'t'`` text mode (default) - ``'+'`` open a disk file for updating (reading and writing) + ``'+'`` open for both reading and writing ``'U'`` :term:`universal newlines` mode (deprecated) ========= =============================================================== The default mode is ``'r'`` (open for reading text, synonym of ``'rt'``). - For binary read-write access, the mode ``'w+b'`` opens and truncates the file - to 0 bytes. ``'r+b'`` opens the file without truncation. + Mode ``'r+'`` opens *file* for both reading and writing, without truncation; + while mode ``'w+'`` truncates the file first. As mentioned in the :ref:`io-overview`, Python distinguishes between binary and text I/O. Files opened in binary mode (including ``'b'`` in the *mode* From 3c870fa3cb5ff0a51c6c5fbae1b98286813f316e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Delfino?= Date: Tue, 25 Dec 2018 16:42:51 -0300 Subject: [PATCH 2/3] Improve wording --- Doc/library/functions.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 1dfe4d102388c1..4d3d26eb77ea70 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -1002,13 +1002,12 @@ are always available. They are listed here in alphabetical order. ``'a'`` open for writing, appending to the end of the file if it exists ``'b'`` binary mode ``'t'`` text mode (default) - ``'+'`` open for both reading and writing + ``'+'`` open for updating (reading and writing) ``'U'`` :term:`universal newlines` mode (deprecated) ========= =============================================================== The default mode is ``'r'`` (open for reading text, synonym of ``'rt'``). - Mode ``'r+'`` opens *file* for both reading and writing, without truncation; - while mode ``'w+'`` truncates the file first. + Mode ``'w+'`` truncates the file. Mode ``'r+'`` does no truncation. As mentioned in the :ref:`io-overview`, Python distinguishes between binary and text I/O. Files opened in binary mode (including ``'b'`` in the *mode* From d2acfdf200cf023d9b26a6a291215d1f117b633a Mon Sep 17 00:00:00 2001 From: Andre Delfino Date: Tue, 19 Mar 2019 15:31:58 -0300 Subject: [PATCH 3/3] =?UTF-8?q?Address=20comment=20from=20R=C3=A9mi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Doc/library/functions.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 6bdc54c9091b2f..09b71293e94dd0 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -1007,7 +1007,8 @@ are always available. They are listed here in alphabetical order. ========= =============================================================== The default mode is ``'r'`` (open for reading text, synonym of ``'rt'``). - Mode ``'w+'`` truncates the file. Mode ``'r+'`` does no truncation. + Modes ``'w+'`` and ``'w+b'`` opens and truncates the file. Modes ``'r+'`` + and ``'r+b'`` opens the file with no truncation. As mentioned in the :ref:`io-overview`, Python distinguishes between binary and text I/O. Files opened in binary mode (including ``'b'`` in the *mode*