Skip to content

Commit 443bc4d

Browse files
serhiy-storchakamiss-islington
authored andcommitted
gh-80678: Document the preferred attribute of csv.Sniffer (GH-155068)
It can be modified to change the order in which the delimiters are preferred for breaking ties. (cherry picked from commit 1370f8a) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent e174896 commit 443bc4d

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

Doc/library/csv.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,8 @@ The :mod:`!csv` module defines the following classes:
316316

317317
If several delimiters fit the sample equally well ---
318318
for example if both ``','`` and ``';'`` split every row consistently ---
319-
the delimiters ``','``, ``'\t'``, ``';'``, ``' '`` and ``':'``
320-
are preferred, in this order,
319+
the delimiters listed in the :attr:`~Sniffer.preferred` attribute
320+
are preferred, in that order,
321321
no matter how many times each of them occurs.
322322

323323
.. method:: has_header(sample)
@@ -339,6 +339,15 @@ The :mod:`!csv` module defines the following classes:
339339
This method is a rough heuristic and may produce both false positives and
340340
negatives.
341341

342+
The :class:`Sniffer` class has the following attribute:
343+
344+
.. attribute:: preferred
345+
346+
The list of the delimiters preferred for breaking ties,
347+
in the order of preference.
348+
It can be modified.
349+
Its initial value is ``[',', '\t', ';', ' ', ':']``.
350+
342351
An example for :class:`Sniffer` use::
343352

344353
with open('example.csv', newline='') as csvfile:

0 commit comments

Comments
 (0)