Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python读取csv到dict引号缺失_Python_Csv - Fatal编程技术网

Python读取csv到dict引号缺失

Python读取csv到dict引号缺失,python,csv,Python,Csv,我有一个标签分隔的csv文件,如下所示: "land"."monkey" "land"."dog" "see"."fish" "see"."shell" 我读了这本书,并用它写了一篇短文: import argparse currentSources = open('currentSources.csv', 'r') find_replace_dict = {} with currentSources as f: reader = csv.reader(f,delimiter=

我有一个标签分隔的csv文件,如下所示:

"land"."monkey" "land"."dog"
"see"."fish"    "see"."shell"
我读了这本书,并用它写了一篇短文:

import argparse
currentSources = open('currentSources.csv', 'r')
find_replace_dict = {}

with currentSources as f:
    reader = csv.reader(f,delimiter='\t')
    find_replace_dict = dict((rows[0],rows[1]) for rows in reader)

print find_replace_dict
我希望find_replace_dict的输出像

{'"land"."monkey"': '"land"."dog"', '"see"."fish"': '"see"."shell"'}
但是,相反,请将其作为:

{'land."monkey"': 'land."dog"', 'see."fish"': 'see."shell"'}
这里缺少土地和see的双引号。 我已经试着告诉读者引用所有的东西

reader = csv.reader(f,delimiter='\t',quoting=csv.QUOTE_NONNUMERIC)
这并没有带来任何区别


如何保留所有双引号?

打开文件时,明确指示Python引号不适用,并将其设置为
None

以下内容应有助于您获得所需的输出:

with currentSources as f:
    reader = csv.reader(f, delimiter='\t', quotechar=None)

通过使用语句删除
,将其整理干净

太好了!就是这样!
reader = csv.reader(currentSources, delimiter='\t', quotechar=None)