Skip to content

Commit 1370f8a

Browse files
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.
1 parent 99b8847 commit 1370f8a

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
@@ -324,8 +324,8 @@ The :mod:`!csv` module defines the following classes:
324324

325325
If several combinations fit the sample equally well ---
326326
for example if both ``','`` and ``';'`` split every row consistently ---
327-
the delimiters ``','``, ``'\t'``, ``';'``, ``' '`` and ``':'``
328-
are preferred, in this order,
327+
the delimiters listed in the :attr:`~Sniffer.preferred` attribute
328+
are preferred, in that order,
329329
no matter how many times each of them occurs.
330330

331331
.. versionchanged:: next
@@ -354,6 +354,15 @@ The :mod:`!csv` module defines the following classes:
354354
This method is a rough heuristic and may produce both false positives and
355355
negatives.
356356

357+
The :class:`Sniffer` class has the following attribute:
358+
359+
.. attribute:: preferred
360+
361+
The list of the delimiters preferred for breaking ties,
362+
in the order of preference.
363+
It can be modified.
364+
Its initial value is ``[',', '\t', ';', ' ', ':']``.
365+
357366
An example for :class:`Sniffer` use::
358367

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

0 commit comments

Comments
 (0)