I'm getting the data from mongodb & using csv.DictWriter method to write the json values to the csv file, but while writing I'm getting a blank line after each row.
How to avoid these blank lines?
Code Snippet: (I'm doing some data manipulation which i didn't include here)
with open('test_output.csv', 'w') as csvfile:
fields = ['date', 'ns', 'storageSize']
writer = csv.DictWriter(csvfile, fieldnames=fields)
writer.writeheader()
stats = client['db_stats'].coll_stats.find({})
for x in stats:
writer.writerow({'date': x["date"], 'ns': x["ns"], 'storageSize': x["storageSize"]});
Output:(with blank lines after each write)