Skip to content

Commit 79cdcee

Browse files
gh-80678: Document the preferred delimiters of csv.Sniffer (#154336)
The delimiters which win when several combinations fit the sample equally well were not documented. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 771abfe commit 79cdcee

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

Doc/library/csv.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,12 @@ The :mod:`!csv` module defines the following classes:
322322
in particular if it is a single column,
323323
so there is no delimiter to find.
324324

325+
If several combinations fit the sample equally well ---
326+
for example if both ``','`` and ``';'`` split every row consistently ---
327+
the delimiters ``','``, ``'\t'``, ``';'``, ``' '`` and ``':'``
328+
are preferred, in this order,
329+
no matter how many times each of them occurs.
330+
325331
.. versionchanged:: next
326332
The dialect is now deduced by trial parsing
327333
and the results may differ from those of earlier Python versions.

Lib/csv.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ def sniff(self, sample, delimiters=None):
260260
beginning, then, after eliminating the combinations which are
261261
clearly worse than the leader, a several times larger part,
262262
and so on.
263+
264+
If several combinations fit the sample equally well, the
265+
delimiters listed in the preferred attribute are preferred, in
266+
that order, no matter how many times each of them occurs.
263267
"""
264268
import re
265269
from collections import defaultdict

0 commit comments

Comments
 (0)