West
West

Reputation: 2570

Appending new row to csv in python

I have a csv of the form:

name,age,country  
john,23,japan  
mel,27,ireland

When I try to append with the following code:

import csv
info=['kirsty','32','germany']
with open('data.csv','a') as file:
    writer=csv.writer(file)
    writer.writerow(info)

file.close()

I get this on opening the file in notepad:

name,age,country  
john,23,japan   
mel,27,irelandkirsty,32,germany

I dont understand why the new entry isn't appending to the next line.

Upvotes: 1

Views: 1538

Answers (1)

Maaaaa
Maaaaa

Reputation: 388

You can add "\n" before each new line.

Upvotes: 1

Related Questions