i had an unique problem. I have code:
with open("test.csv", "r") as csvFile:
reader = csv.reader(csvFile, skipinitialspace=True)
for row in reader:
for obj in row:
print(obj)
并且有一个示范csv文件:
anotherCommand, e=5, f=6, g=7, h=9, test="aaa, bbb, ggggg"
我想按照以下方式拆分这个字符串:
anotherCommand
e=5
f=6
g=7
h=9
test="aaa, bbb, ggggg"
但是我看到的代码将这些字符串按照以下方式拆分:
anotherCommand
e=5
f=6
g=7
h=9
test="aaa
bbb
ggggg"
这是错误的解决方案。 我看到了这样的话题: 为什么Python CSV阅读器忽略了双引号字段? 或者 如何将逗号分隔的字符串解析为列表(注意事项)? 但是这个例子不同,而且这些例子都没有达到我的期望。 有人有想法吗?