Skip to content

Commit 3f7cc33

Browse files
serhiy-storchakaclaude
authored andcommitted
[3.14] 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 37a5c69 commit 3f7cc33

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
@@ -243,6 +243,10 @@ def __init__(self):
243243
def sniff(self, sample, delimiters=None):
244244
"""
245245
Returns a dialect (or None) corresponding to the sample
246+
247+
If several combinations fit the sample equally well, the
248+
delimiters listed in the preferred attribute are preferred, in
249+
that order, no matter how many times each of them occurs.
246250
"""
247251

248252
quotechar, doublequote, delimiter, skipinitialspace = \

0 commit comments

Comments
 (0)