[英]Python CSV : field containing quotation mark at the beginning
我正在嘗試讀取包含以下行的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()
...
默認情況下"
是Python的csv
模塊的引用字符 。使用
csv.reader(open('.info.csv'), skipinitialspace=True, quotechar=None)
禁用此默認值。 您給出的示例將導致記錄
['test', '"test', '"test', 'test', 'test', 'test']
您可以將quoting=csv.QUOTE_NONE
參數添加到reader()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.