Skip to content
Open
Changes from 2 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
19 changes: 18 additions & 1 deletion Doc/library/csv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -636,7 +653,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 <universal newlines>`) newline handling.
Loading