From 79cdcee308c6612edd6d1ca972342e2a088b6b4e Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 22 Jul 2026 15:20:08 +0300 Subject: [PATCH] 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) --- Doc/library/csv.rst | 6 ++++++ Lib/csv.py | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst index 36db964a8bbf..81949261c563 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 505e9e501e67..a84234f110dd 100644 --- a/Lib/csv.py +++ b/Lib/csv.py @@ -260,6 +260,10 @@ class Sniffer: 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 -- 2.47.3