Skip to content

gh-155059: Add the *delimiters* parameter in the csv.Sniffer constructor - #155060

Open
serhiy-storchaka wants to merge 2 commits into
python:mainfrom
serhiy-storchaka:csv-sniffer-delimiters
Open

gh-155059: Add the *delimiters* parameter in the csv.Sniffer constructor#155060
serhiy-storchaka wants to merge 2 commits into
python:mainfrom
serhiy-storchaka:csv-sniffer-delimiters

Conversation

@serhiy-storchaka

@serhiy-storchakaserhiy-storchaka commented Aug 1, 2026

Copy link
Copy Markdown
Member

The csv.Sniffer constructor now accepts an optional delimiters argument, used by both sniff() and has_header(), which previously had no way to restrict the delimiters. The delimiters argument of sniff() still takes precedence.

The given delimiters are also preferred in that order for breaking ties: csv.Sniffer(';,') guesses ';' where csv.Sniffer(',;') guesses ','.

…tructor
It is used by both sniff() and has_header(), and its characters are
preferred, in the given order, for breaking ties.
@read-the-docs-community

read-the-docs-communityBot commented Aug 1, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33882939 | 📁 Comparing c97bc4f against main (7b4165b)

🔍 Preview build

5 files changed · ± 5 modified

±Modified

Comment threadLib/csv.py Outdated
def __init__(self):
# in case there is more than one possible delimiter
self.preferred = [',', '\t', ';', ' ', ':']
def __init__(self, delimiters=None):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use keyword-only arguments here? csv.Sniffer(delimiters=",;") is more readable than csv.Sniffer(",;")

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@serhiy-storchaka@dolfinus