基本上,我可以知道如何在代码中添加quote_none
吗?我正在使用Python 3.7。我正在尝试使其尽可能简单。
csvFile = csv.reader(open("cats.csv",'r'))
header = next(csvFile)
index = 1
print (header)
print("")
for row in csvFile :
if row[1] >= "35" :
print (row)
index +=1
这就是我得到的:
1 ['Oliver', '12', 'HOPE']
2 ['Leo', '16', 'SPCA', '']
3 ['Milo', '13', 'ISPCA', ']
4 ['Jack', '12', 'SPCA', ']
5 ['George', '14', 'HOPE']
6 ['Bella', '10', 'FFF', ']
7 ['Cleo', '14', 'SPCA', '']
8 ['Nala', '16', 'ISPCA', '']
9 ['Teddy', '12', 'SPCA', ']
10 ['Zeus', '16', 'SPCA', '']
11 ['Louie', '14', 'LOVS', '']
12 ['Apollo', '11', 'FFF', '' ]
13 ['George', '10', 'SPCA', '']
14 ['Ziggy', '11', 'ISPCA', ']
预期结果:
1 ['Oliver,12,HOPE']
2 ['Leo,16,SPCA']
3 ['Charlie,18,SPCA']
4 ['Milo,13,ISPCA']
5 ['Jack,12,SPCA']
6 ['George,14']
7 ['Simon,22,SPCA']
8 ['Loki,24,SPCA']
9 ['Simba,23,SPCA']
答案 0 :(得分:1)
使用join
:
lst = ['Oliver', '12', 'HOPE']
print([','.join(lst)])
所以,在您的示例中,我想这是:
print([','.join(row)])