Python csv blank line problem

Write to csv

with open(birth_weight_file,'w') as f:
    writer=csv.writer(f)
    writer.writerow(birth_header)
    writer.writerows(birth_data)
    f.close()

copy

The final result of this writing method is that the generated csv file has a blank line between every two lines. The solution is to add newline='' after open.

Writing method:

with open(birth_weight_file,'w',newline='') as f:
    writer=csv.writer(f)
    writer.writerow(birth_header)
    writer.writerows(birth_data)
    f.close()

Guess you like

Origin blog.csdn.net/qq_34626094/article/details/112919541