Skip to content

Commit df1218e

Browse files
hugovkserhiy-storchakaclaude
authored
[3.15] gh-80678: Document the preferred delimiters of csv.Sniffer (GH-154336) (#154589)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent a19a086 commit df1218e

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
@@ -312,6 +312,11 @@ The :mod:`!csv` module defines the following classes:
312312
is given, it is interpreted as a string containing possible valid
313313
delimiter characters.
314314

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

316321
.. method:: has_header(sample)
317322

Lib/csv.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ def __init__(self):
241241
def sniff(self, sample, delimiters=None):
242242
"""
243243
Returns a dialect (or None) corresponding to the sample
244+
245+
If several delimiters fit the sample equally well, the
246+
delimiters listed in the preferred attribute are preferred, in
247+
that order, no matter how many times each of them occurs.
244248
"""
245249

246250
quotechar, doublequote, delimiter, skipinitialspace = \

0 commit comments

Comments
 (0)