Also note that from doc:分析给定的样本并返回一个反映以下内容的方言子类 找到的参数.如果给出了可选的delimiters参数, 它被解释为包含可能的有效定界符的字符串 字符.Analyze the given sample and return a Dialect subclass reflecting the parameters found. If the optional delimiters parameter is given, it is interpreted as a string containing possible valid delimiter characters.因此,如果要在文本文件中找到的分隔符类似于#而不是,或;,那么您应该在sniff函数中提到它是第二个参数,如下所示:Hence if the delimiter that you want to find in your text file is something like # instead of , or ; then you should mention that in sniff function as second parameter like this:dialect = csv.Sniffer().sniff(f1.read(1024), '#') 更新:要读取整个文件,您将需要Update: For reading whole file you will needdialect = csv.Sniffer().sniff(f1.read()) 这篇关于在txt中找到定界符以使用Python转换为csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-23 15:02