检测CSV、TSV和其他特殊文件格式中使用的分隔符。
detect-delimiter的Python项目详细描述
检测分隔符
关于
检测CSV、TSV和其他特殊文件格式中使用的分隔符。
安装
使用pip install detect_delimiter
用法
detect_delimiter
公开了detect()
函数,它需要一个str
作为输入并返回分隔符。
>>> from detect_delimiter import detect
>>> detect("looks|like|the vertical bar\n is|the|delimiter\n")
'|'
当detect()
不知道时,它返回None
:
>>> text = "not really any delimiters in here.\nthis is just text.\n"
>>> detect()
可以提供默认值,在这种情况下将使用该值:
>>> detect(text, default=',')
','
默认情况下,detect()
将阻止检查字母数字字符
句点/句号(“.”)。这可以通过
blacklist
参数。
如果您相信您知道分隔符,则可以提供
通过whitelist
参数检查的可能分隔符列表。
如果不提供值,[',', ';', ':', '|', '\t']
将被选中。
测试
您可以直接从项目的根目录使用pytest
或tox
。