CSV generated empty row of each line

If I create an csv file,

python generated after single row an empty row .

Why is this so. In example of Mosh isn’t this behaivor.
Bute I have empty row after header and each data-rows.

Hi there this could be happening because you maybe inadvertently adding a new line after writing each row possibly by adding the new line character or somehow adding a blank line. Do go back and double check your code for any hint of this.

Otherwise you could explictly pass a keyword argument of newline='' to the open function to prevent this from happening. So your code could look something like:

import csv

data = [
    ["Name", "Age", "Country"],
    ["John", 30, "USA"],
    ["Jane", 25, "Canada"],
    ["Mike", 40, "UK"],

filename = "data.csv"

# Use newline='' to avoid extra newline characters
with open(filename, mode='w', newline='') as file:
    writer = csv.writer(file)
1 Like

Hey it’s work.

thank so lot.

I am wondering, why Mosh doesn’t update they own courses.