Skip to content

gh-80678: Add comment on preferred csv delimiters - #96199

Closed
slateny wants to merge 2 commits into
python:mainfrom
slateny:s/80678
Closed

gh-80678: Add comment on preferred csv delimiters#96199
slateny wants to merge 2 commits into
python:mainfrom
slateny:s/80678

Conversation

@slateny

@slatenyslateny commented Aug 23, 2022

Copy link
Copy Markdown
Contributor

https://docs.python.org/dev/library/csv.html#csv.Sniffer.sniff

See

self.preferred= [',', '\t', ';', ' ', ':']
for the list of preferred delimiters, and see

cpython/Lib/csv.py

Lines 369 to 375 in 1499d73

# if there's more than one, fall back to a 'preferred' list
iflen(delims) >1:
fordinself.preferred:
ifdindelims.keys():
skipinitialspace= (data[0].count(d) ==
data[0].count("%c "%d))
return (d, skipinitialspace)
for choosing the preferred delimiters

Comment threadDoc/library/csv.rst Outdated
Comment threadDoc/library/csv.rst
reflecting the parameters found. If the optional *delimiters* parameter
is given, it is interpreted as a string containing possible valid
delimiter characters.
If not excluded by the *delimiters* parameter, and if there is ambiguity,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is the documentation here not added to the def sniff docstring? That would be a natural place for documentation that is available from the command line or IDE.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'm not sure what information should go into the docstring vs in the docs. I imagine there's some duplicate, but surely not everything in the docs goes into the docstring and vice-versa. The docstring of sniff is looking a bit empty though, so it could use some work for sure.

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
@slatenyslateny changed the title gh-80678: Add comment on preferred delimitersgh-80678: Add comment on preferred csv delimitersJan 8, 2023
@python-cla-bot

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

CLA signed

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actionsgithub-actionsBot added the stale Stale PR or inactive for long period of time. label Apr 11, 2026
Comment threadDoc/library/csv.rst
is given, it is interpreted as a string containing possible valid
delimiter characters.
If not excluded by the *delimiters* parameter, and if there is ambiguity,
then delimiter choice will be biased towards ``[',', '\t', ';', ' ', ':']``.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a little inaccurate, it is in that specific order. Maybe something like ",, ... : in that order"

@github-actionsgithub-actionsBot removed the stale Stale PR or inactive for long period of time. label Jun 13, 2026
@serhiy-storchaka

Copy link
Copy Markdown
Member

Thank you for the patch, and sorry that it was left without attention for so long.

I documented this in GH-154336, with the order made explicit and with a note that the preference wins no matter how many times each delimiter occurs, which is the case reported in the issue.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviewdocsDocumentation in the Doc dirskip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

5 participants

@slateny@serhiy-storchaka@eendebakpt@StanFromIreland@bedevere-bot