From 0df538868f5f3f858507f836b1379d099a46d129 Mon Sep 17 00:00:00 2001 From: maurycy <5383+maurycy@users.noreply.github.com> Date: Wed, 20 Aug 2025 20:44:11 +0200 Subject: [PATCH 1/4] typo --- Doc/library/csv.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst index d39c4ca4a5838b..1bb36a18b4277a 100644 --- a/Doc/library/csv.rst +++ b/Doc/library/csv.rst @@ -636,7 +636,7 @@ done:: .. rubric:: Footnotes .. [1] If ``newline=''`` is not specified, newlines embedded inside quoted fields - will not be interpreted correctly, and on platforms that use ``\r\n`` linendings + will not be interpreted correctly, and on platforms that use ``\r\n`` line endings on write an extra ``\r`` will be added. It should always be safe to specify ``newline=''``, since the csv module does its own (:term:`universal `) newline handling. From 6e4b9a5ab5b27a7327559bfafad8ab55c17c8da6 Mon Sep 17 00:00:00 2001 From: maurycy <5383+maurycy@users.noreply.github.com> Date: Wed, 20 Aug 2025 21:01:52 +0200 Subject: [PATCH 2/4] describe the behavior --- Doc/library/csv.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst index 1bb36a18b4277a..8e59a45d375a08 100644 --- a/Doc/library/csv.rst +++ b/Doc/library/csv.rst @@ -469,6 +469,23 @@ Dialects support the following attributes: When :const:`True`, spaces immediately following the *delimiter* are ignored. The default is :const:`False`. + .. note:: + + When combining ``delimiter=' '`` (a space) with ``skipinitialspace=True``, + the writer must quote empty fields. + + If an unquoted empty field would be emitted (for example writing ``''`` or + values that become empty like :data:`None` under some quoting modes), + :class:`writer` raises :exc:`csv.Error`. Quoting (the default + :data:`QUOTE_MINIMAL` is sufficient) avoids this error. + + Example:: + + >>> import csv, io + >>> buf = io.StringIO() + >>> w = csv.writer(buf, delimiter=' ', skipinitialspace=True, + ... quoting=csv.QUOTE_NONE) + >>> w.writerow(['', 'x']) # raises csv.Error .. attribute:: Dialect.strict From 3bf1d88c0e19fb9e1fad94e4cc5a36d3802ab7a7 Mon Sep 17 00:00:00 2001 From: maurycy <5383+maurycy@users.noreply.github.com> Date: Thu, 21 Aug 2025 12:52:52 +0200 Subject: [PATCH 3/4] just one sentence --- Doc/library/csv.rst | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst index 8e59a45d375a08..3aa1a8a83136ab 100644 --- a/Doc/library/csv.rst +++ b/Doc/library/csv.rst @@ -467,25 +467,8 @@ Dialects support the following attributes: .. attribute:: Dialect.skipinitialspace When :const:`True`, spaces immediately following the *delimiter* are ignored. - The default is :const:`False`. - - .. note:: - - When combining ``delimiter=' '`` (a space) with ``skipinitialspace=True``, - the writer must quote empty fields. - - If an unquoted empty field would be emitted (for example writing ``''`` or - values that become empty like :data:`None` under some quoting modes), - :class:`writer` raises :exc:`csv.Error`. Quoting (the default - :data:`QUOTE_MINIMAL` is sufficient) avoids this error. - - Example:: - - >>> import csv, io - >>> buf = io.StringIO() - >>> w = csv.writer(buf, delimiter=' ', skipinitialspace=True, - ... quoting=csv.QUOTE_NONE) - >>> w.writerow(['', 'x']) # raises csv.Error + The default is :const:`False`. When combining ``delimiter=' '`` with + ``skipinitialspace=True``, unquoted empty fields are not allowed. .. attribute:: Dialect.strict From eb5ea6a8dc168f8bceb977dae838ceb8ee159271 Mon Sep 17 00:00:00 2001 From: maurycy <5383+maurycy@users.noreply.github.com> Date: Thu, 21 Aug 2025 12:53:20 +0200 Subject: [PATCH 4/4] bring back trailing space --- Doc/library/csv.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst index 3aa1a8a83136ab..4242fc51ab395c 100644 --- a/Doc/library/csv.rst +++ b/Doc/library/csv.rst @@ -470,6 +470,7 @@ Dialects support the following attributes: The default is :const:`False`. When combining ``delimiter=' '`` with ``skipinitialspace=True``, unquoted empty fields are not allowed. + .. attribute:: Dialect.strict When ``True``, raise exception :exc:`Error` on bad CSV input.