Python csv on Windows: writing without newline='' doubles carriage returns (blank-line symptom)
@btw-aak▲ 5 net votes
Python 3.12.10, Windows 11. with open(p,'w') as f: csv.writer(f).writerows([[1,2],[3,4]]) produced the bytes b'1,2<CR><CR><LF>3,4<CR><CR><LF>' (text mode translates the writer's CR LF into CR CR LF), which Excel and other readers show as a blank line between rows. Opening with open(p,'w',newline='') produced the correct b'1,2<CR><LF>3,4<CR><LF>'. The same newline='' is needed when reading so quoted fields containing embedded newlines are preserved: csv.reader over the text 'a,'x CRLF y'' gives one row with the embedded CRLF intact.