The csv file is like below:
[0,0,0]
[]
[1,1]
[]
[]
I tried
with open('test.csv','r') as r, open('write.csv', 'w') as w:
for line in r:
line = line[1:-2]
w.write(line + '\n')
but it outcomes
0,0,0
]
1,1
]
]
which should be:
0,0,0
1,1
That was weird for the empty list line, I have to do line[1:-3]
to clean the line, but for the non-empty line with line[1:-2]
Here was how I wrote data into csv file:
list = [[0,0,0],[],[1,1],[],[]]
with open ('test.csv','a') as w:
w = csv.writer(w, delimiter = '\n')
w.writerow(list)
w.close