8000 gh-67230: add quoting rules to csv module by smontanaro · Pull Request #29469 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-67230: add quoting rules to csv module #29469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions Doc/library/csv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ The :mod:`csv` module defines the following constants:

Instructs :class:`writer` objects to quote all non-numeric fields.

Instructs the reader to convert all non-quoted fields to type *float*.
Instructs :class:`reader` to convert all non-quoted fields to type *float*.


.. data:: QUOTE_NONE
Expand All @@ -342,14 +342,20 @@ The :mod:`csv` module defines the following constants:
.. data:: QUOTE_NOTNULL

Instructs :class:`writer` objects to quote all fields which are not
``None``. If a field value is ``None`` an empty (unquoted) string
is written.
``None``. This is similar to QUOTE_ALL, except that if a
field value is ``None`` an empty (unquoted) string is written.

Instructs :class:`reader` to interpret an empty (unquoted) field as None, and
otherwise behave as QUOTE_ALL.

.. data:: QUOTE_STRINGS

Instructs :class:`writer` quotes are always placed around fields
which are strings. Note that ``None`` will be written as a
bar (unquoted) empty string.
Instructs :class:`writer` objects to always place quotes around fields
which are strings. This is similar to QUOTE_NONNUMERIC, except that if a
field value is ``None`` an empty (unquoted) string is written.

Instructs :class:`reader` to interpret an empty (unquoted) string as None, and
otherwise behave as QUOTE_NONNUMERIC.

The :mod:`csv` module defines the following exception:

Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ def test_write_quoting(self):
quoting = csv.QUOTE_ALL)
self._write_test(['a\nb',1], '"a\nb","1"',
quoting = csv.QUOTE_ALL)
self._write_test(['a',None,1], '"a",,1',
self._write_test(['a','',None,1], '"a","",,1',
quoting = csv.QUOTE_STRINGS)
self._write_test(['a',None,1], '"a",,"1"',
self._write_test(['a','',None,1], '"a","",,"1"',
quoting = csv.QUOTE_NOTNULL)

def test_write_escape(self):
Expand Down
0