我正在用Python解析写得不好的csv
文件,我想知道,有没有办法在Python csv.reader
中有多个引号字符?
例如,我的文件如下所示:
somedata, "some other data which is a string", [1,2,3,4]
moredata, "more data which may have commas ,", [12]
我想做的是做这样的事情:
import csv
with open('myfile.csv') as f:
r = csv.reader(quotechar='"', delimiter=',', bracketchar='[]')
for row in r:
print row[0]
这会产生类似
的内容['1', '2', '3', '4']
['12']
或至少类似的东西。当然,我可以通过简单地阅读文件来实现这一点,但我觉得csv
模块可以实现更优雅的解决方案...