Python Csv Library Leaves Empty Rows Even When Using A Valid Lineterminator
I am trying to fetch data from the internet to save it to a csv file. I am facing a problem with writing to the csv file, the library leaves an empty row in the file The data is r
Solution 1:
Updated Answer
If when you create the list that is being written to the data
list, if you add it as a list so that data
becomes a list of lists, then set your line delimiter to be '\n'
, it should work. Below is the working code I used to test.
import csv
import random
csvfile = open('csvTest.csv', 'a')
data = []
for x in range(5):
data.append([str(random.randint(0, 100))])
writer = csv.writer(csvfile, lineterminator = '\n')
writer.writerows(data)
csvfile.close()
and it outputs
Post a Comment for "Python Csv Library Leaves Empty Rows Even When Using A Valid Lineterminator"