python / python/cpython

Add a delimiters parameter to the csv.Sniffer constructor

未關閉
#155,059 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

3.16 stdlib type-feature
主要語言
Python
星號
77.2k
分支
36k
平均合併
1 天 9 小時
30 天內合併 PR
558

描述

Feature or enhancement

csv.Sniffer.sniff() accepts an optional delimiters argument which restricts the set of characters that can be guessed as a delimiter. has_header() has no such argument, so the restriction cannot be applied to it.

I propose to add an optional delimiters parameter to the constructor, so that it applies to the sniffer rather than to a single call:

sniffer = csv.Sniffer(',;\t')
if sniffer.has_header(sample):
    ...
dialect = sniffer.sniff(sample)

It is used by both sniff() and has_header(). The delimiters argument of sniff(), if given, still takes precedence.

The given delimiters are also preferred in that order if several of them split the sample equally well: csv.Sniffer(';,') guesses ';' where csv.Sniffer(',;') guesses ','.

Linked PRs
  • gh-155060

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

先從 issue 中描述的 csv.Sniffer、sniff() 和 has_header() 進入點開始,然後檢查現有的 CSV 測試以了解其目前行為。完成的標準是:兩個方法都使用建構函式的 delimiters 限制,sniff() 可以覆寫該限制,而且相同的候選項遵循所提供的分隔符號順序。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
data
Issue 類型
功能
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
描述清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。