Skip to content

Document that CSV skipinitialspace=True and delimiter=' ' require quotation for empty fields #138005

@maurycy

Description

@maurycy

skipinitialspace=True and delimiter=' ' raise an exception for an unquoted blank field:

The docs do not mention this behavior:

Simple demonstration:

>>> import csv, io
>>> buf = io.StringIO()
>>> w = csv.writer(buf, delimiter=' ', skipinitialspace=True, quoting=csv.QUOTE_NONE)
>>> w.writerow(['', 'x'])
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    w.writerow(['', 'x'])
    ~~~~~~~~~~^^^^^^^^^^^
_csv.Error: empty field must be quoted if delimiter is a space and skipinitialspace is true

This is since gh-115721. The behavior is intentional and the docs should be updated.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Status

    No status

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions