Why does CSV file contain a blank line in between each data line when outputting with Dictwriter in Python [duplicate]

By default, the classes in the csv module use Windows-style line terminators (\r\n) rather than Unix-style (\n). Could this be what’s causing the apparent double line breaks?

If so, in python 2 you can override it in the DictWriter constructor:

output = csv.DictWriter(open('file3.csv','w'), delimiter=",", lineterminator="\n", fieldnames=headers)

Leave a Comment