KITFORMA · EDITORIAL ANSWER
Why does a CSV export contain extra blank rows on Windows?
KitForma editorial guide. Let Python’s csv writer manage line endings and verify logical rows, including quoted commas and embedded newlines.
Step-by-step answer
import csv
import tempfile
from pathlib import Path
rows = [["sku", "description"], ["00125", "Blue, large\nSecond line"]]
with tempfile.TemporaryDirectory() as directory:
path = Path(directory) / "products.csv"
with path.open("w", encoding="utf-8", newline="") as handle:
csv.writer(handle).writerows(rows)
with path.open("r", encoding="utf-8", newline="") as handle:
restored = list(csv.reader(handle))
print("rows:", len(restored))
print("sku:", restored[1][0])
print("multiline preserved:", restored == rows)
print("extra CR:", b"\r\r\n" in path.read_bytes())rows: 2
sku: 00125
multiline preserved: True
extra CR: FalseSources and verification
Sources checked:
This editorial answer was prepared by KitForma with AI assistance. It is not presented as a real member question or an independent user review. Check the sources and the result with your own file; report corrections in the discussion.