Skip to content
Open
Changes from all 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: 18 additions & 0 deletions Doc/library/csv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ The :mod:`!csv` module defines the following functions:
dialect. For full details about the dialect and formatting parameters, see
section :ref:`csv-fmt-params`.

.. note::
If *csvfile* is an iterable of strings (such as a list) and the CSV format
contains quoted fields with embedded newlines, ensure that the strings
retain their newline characters. For example, using :meth:`~str.splitlines`
without ``keepends=True`` will strip these newlines, causing them to be
lost when the quoted fields are reconstructed.

Each row read from the csv file is returned as a list of strings. No
automatic data type conversion is performed unless the :data:`QUOTE_NONNUMERIC` format
option is specified (in which case unquoted fields are transformed into floats).
Expand Down Expand Up @@ -711,6 +718,17 @@ done::
for row in csv.reader(['one,two,three']):
print(row)

If the string contains quoted fields with embedded newlines, use
:meth:`~str.splitlines` with ``keepends=True`` to ensure the newlines
are preserved::

import csv
text = '''"Id (id)","Comments (comments)"
"195","This is a
multiline comment"'''
for row in csv.reader(text.splitlines(True)):
print(row)


.. rubric:: Footnotes

Expand Down
Loading