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
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

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 摘要。