gpt4 book ai didi

python - 读取 csv.Sniffer() 的输出

转载 作者:太空宇宙 更新时间:2023-11-03 21:26:00 26 4
gpt4 key购买 nike

我有一个文件,使用 \x01 作为字段分隔符,使用 \x02\n 作为行终止符。以下是文件头的示例:

 #export_date\x01artist_id\x01name\x01is_actual_artist\x01view_url\x01artist_type_id\x02\n

当我使用csv.Sniffer()时,我得到以下结果:

{'module': 'csv', '_name': 'sniffed', 'lineterminator': '\r\n', 'quoting': 0, 'doc': None, 'doublequote': False, 'delimiter': '\x01', 'quotechar': '"', 'skipinitialspace': False}

以下三个字段的含义:

  • 引用
  • 引用字符
  • 双引号

上面没有任何引用,所以我假设 quotechar 应该为空而不是双引号,但是对这三个字段的任何解释都很好。

此外,我还尝试了其他一些文件,它似乎总是给出这三个字段的准确输出,无论该文件是否有引用。

最佳答案

查看文档

  • 方言.双引号

Controls how instances of quotechar appearing inside a field should themselves be quoted. When True, the character is doubled. When False, the escapechar is used as a prefix to the quotechar. It defaults to True.

  • 方言.quotechar

A one-character string used to quote fields containing special characters, such as the delimiter or quotechar, or which contain new-line characters. It defaults to '"'.

  • 方言引用

Controls when quotes should be generated by the writer and recognised by the reader. It can take on any of the QUOTE_* constants (see section Module Contents) and defaults to QUOTE_MINIMAL.

关于python - 读取 csv.Sniffer() 的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53838501/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com