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?

  1. A.

    FileNotFoundError

  2. B.

    Extra blank lines between rows

  3. C.

    End-of-file error

  4. 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.

Explore the full course: Rssb Senior Computer Instructor