1 回答

TA贡献1804条经验 获得超8个赞
这是获取结果的演示:
In []:
data = """'1', '"For Those About To Rock We Salute You"', 'Album'
'2', '"Balls to the Wall"', 'Album'
'3', '"Restless and Wild"', 'Album'
'4', '"Let There Be Rock"', 'Album'
'5', '"Big Ones"', 'Album'
'6', '"Jagged Little Pill"', 'Album'"""
import csv
with StringIO(data) as fin:
reader = csv.reader(fin, quotechar="'", skipinitialspace=True)
for row in reader:
print(row)
Out[]:
['1', '"For Those About To Rock We Salute You"', 'Album']
['2', '"Balls to the Wall"', 'Album']
['3', '"Restless and Wild"', 'Album']
['4', '"Let There Be Rock"', 'Album']
['5', '"Big Ones"', 'Album']
['6', '"Jagged Little Pill"', 'Album']
In []:
with StringIO(data) as fin, StringIO() as fout:
reader = csv.reader(fin, quotechar="'", skipinitialspace=True)
writer = csv.writer(fout, quotechar='', quoting=csv.QUOTE_NONE)
writer.writerows(reader)
contents = fout.getvalue()
print(contents)
Out[]:
1,"For Those About To Rock We Salute You",Album
2,"Balls to the Wall",Album
3,"Restless and Wild",Album
4,"Let There Be Rock",Album
5,"Big Ones",Album
6,"Jagged Little Pill",Album
添加回答
举报