python / python/cpython

Feature request: sniff csv quoting and lineterminator

Open
#129,374 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

3.16 stdlib type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

If you read a csv file, alter the data and then write it back, it would be very nice to recreate also the quoting behaviour. So e.g. if the file is quoted in style csv.QUOTE_NONNUMERIC, it would be very useful to have the quoting property set correctly in the dialect object returned by csv.Sniffer().sniff.
Also, I just figured out that the line terminator is also hard-coded to "\r\n". Would also be nice to be adaptive...

Linked PRs
  • gh-134416

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Lib/csv.py around csv.Sniffer().sniff, the entry point named in the issue, and review linked PR gh-134416 for the current work. The change is complete when sniffed dialects preserve the input quoting behavior and line terminator instead of using fixed defaults.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.