1 回答

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超8個(gè)贊
這是獲取結(jié)果的演示:
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
添加回答
舉報(bào)