【发布时间】:2015-09-24 08:30:16
【问题描述】:
我正在尝试从 csv 文件创建一个列表。但是,我在使用 split 方法时遇到了困难,因为 csv 文件中的某些属性在括号内有逗号。例如:
csv file:
500,403,34,"hello there, this attribute has a comma in it",567
例如,当我遍历文件时:
for line in f:
fields = line.split(",")
fields = ['500','403','34','"hello there','this attribute has a comma in it"','567']
我怎样才能让它看起来像这样:
fields = ['500','403','34','"hello there, this attribute has a comma in it"','567']
我想为此使用正则表达式,但如果有更简单的方法,我很想听听。谢谢!
【问题讨论】: