Skip to content

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

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

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

Conversation

@slateny

@slateny slateny 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
if len(delims) > 1:
for d in self.preferred:
if d in delims.keys():
skipinitialspace = (data[0].count(d) ==
data[0].count("%c " % d))
return (d, skipinitialspace)
for choosing the preferred delimiters

@bedevere-bot bedevere-bot added docs Documentation in the Doc dir skip news awaiting review labels Aug 23, 2022
Comment thread Doc/library/csv.rst Outdated
Comment thread Doc/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
Contributor Author

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>
@slateny slateny changed the title gh-80678: Add comment on preferred delimiters gh-80678: Add comment on preferred csv delimiters Jan 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-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 11, 2026
Comment thread Doc/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-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

4 participants