Skip to content

Commit 5c4ba45

Browse files
serhiy-storchakaclaude
authored andcommitted
[3.13] gh-80678: Document the preferred delimiters of csv.Sniffer (GH-154336)
The delimiters which win when several combinations fit the sample equally well were not documented. (cherry picked from commit 79cdcee) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 233022d commit 5c4ba45

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

Doc/library/csv.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,11 @@ The :mod:`csv` module defines the following classes:
314314
is given, it is interpreted as a string containing possible valid
315315
delimiter characters.
316316

317+
If several combinations fit the sample equally well ---
318+
for example if both ``','`` and ``';'`` split every row consistently ---
319+
the delimiters ``','``, ``'\t'``, ``';'``, ``' '`` and ``':'``
320+
are preferred, in this order,
321+
no matter how many times each of them occurs.
317322

318323
.. method:: has_header(sample)
319324

Lib/csv.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ def __init__(self):
244244
def sniff(self, sample, delimiters=None):
245245
"""
246246
Returns a dialect (or None) corresponding to the sample
247+
248+
If several combinations fit the sample equally well, the
249+
delimiters listed in the preferred attribute are preferred, in
250+
that order, no matter how many times each of them occurs.
247251
"""
248252

249253
quotechar, doublequote, delimiter, skipinitialspace = \

0 commit comments

Comments
 (0)