While writing data to a CSV file in Python on the Windows operating system,…
2026
While writing data to a CSV file in Python on the Windows operating system, the file is often opened using the argument newline=''. What problem does specifying newline=' ' prevent?
- A.
FileNotFoundError
- B.
Extra blank lines between rows
- C.
End-of-file error
- D.
Data duplication
Attempted by 540 students.
Show answer & explanation
Correct answer: B
The correct answer is Option B (Extra blank lines between rows).
In Python, when writing to a CSV file on Windows, if newline='' is not specified, extra blank lines may appear between rows. This happens due to the way newline characters are handled by the operating system and the csv module.
Specifying newline='' prevents this issue and ensures proper formatting of rows.