Skip to content

Commit 6e4b9a5

Browse files
committed
describe the behavior
1 parent 0df5388 commit 6e4b9a5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Doc/library/csv.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,23 @@ Dialects support the following attributes:
469469
When :const:`True`, spaces immediately following the *delimiter* are ignored.
470470
The default is :const:`False`.
471471

472+
.. note::
473+
474+
When combining ``delimiter=' '`` (a space) with ``skipinitialspace=True``,
475+
the writer must quote empty fields.
476+
477+
If an unquoted empty field would be emitted (for example writing ``''`` or
478+
values that become empty like :data:`None` under some quoting modes),
479+
:class:`writer` raises :exc:`csv.Error`. Quoting (the default
480+
:data:`QUOTE_MINIMAL` is sufficient) avoids this error.
481+
482+
Example::
483+
484+
>>> import csv, io
485+
>>> buf = io.StringIO()
486+
>>> w = csv.writer(buf, delimiter=' ', skipinitialspace=True,
487+
... quoting=csv.QUOTE_NONE)
488+
>>> w.writerow(['', 'x']) # raises csv.Error
472489

473490
.. attribute:: Dialect.strict
474491

0 commit comments

Comments
 (0)