我正在尝试阅读包含以下行的CSV文件:
test,"test,"test,test,test,test
引号存在问题(有六个字段,但它们被检索为五个字段,因为“test”,测试被读作单个字段)。
我已尝试按如下方式修改条目,但仍无法检索引号:
test,""test,""test,test,test,test # quotation marks disappear when the entry is read.
test,\"test,\"test,test,test,test # backslashes are also retrieved; escaping doesn't seem to work.
我正在以这种方式阅读CSV文件:
info_source = csv.reader(open('.info.csv'), skipinitialspace=True)
for row in ling_info_source:
data = row[1].strip()
...
答案 0 :(得分:3)
默认情况下,"
是Python的csv
模块的quoting character。使用
csv.reader(open('.info.csv'), skipinitialspace=True, quotechar=None)
禁用此默认值。您提供的示例将生成记录
['test', '"test', '"test', 'test', 'test', 'test']
答案 1 :(得分:3)
您可以将quoting=csv.QUOTE_NONE
参数添加到reader()