https://github.com/python/cpython/commit/79cdcee308c6612edd6d1ca972342e2a088b6b4e commit: 79cdcee308c6612edd6d1ca972342e2a088b6b4e branch: main author: Serhiy Storchaka <[email protected]> committer: ambv <[email protected]> date: 2026-07-22T14:20:08+02:00 summary:
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) <[email protected]> files: M Doc/library/csv.rst M Lib/csv.py diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst index 36db964a8bbfe4..81949261c563d0 100644 --- a/Doc/library/csv.rst +++ b/Doc/library/csv.rst @@ -322,6 +322,12 @@ The :mod:`!csv` module defines the following classes: in particular if it is a single column, so there is no delimiter to find. + If several combinations fit the sample equally well --- + for example if both ``','`` and ``';'`` split every row consistently --- + the delimiters ``','``, ``'\t'``, ``';'``, ``' '`` and ``':'`` + are preferred, in this order, + no matter how many times each of them occurs. + .. versionchanged:: next The dialect is now deduced by trial parsing and the results may differ from those of earlier Python versions. diff --git a/Lib/csv.py b/Lib/csv.py index 505e9e501e6772..a84234f110dd70 100644 --- a/Lib/csv.py +++ b/Lib/csv.py @@ -260,6 +260,10 @@ def sniff(self, sample, delimiters=None): beginning, then, after eliminating the combinations which are clearly worse than the leader, a several times larger part, and so on. + + If several combinations fit the sample equally well, the + delimiters listed in the preferred attribute are preferred, in + that order, no matter how many times each of them occurs. """ import re from collections import defaultdict _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
