1

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.

5
  • 3
    Probably the original file is missing a final newline \n. Commented Apr 13, 2018 at 12:37
  • Agreed. So something like writer.writerow("\n") before you write the info Commented Apr 13, 2018 at 12:38
  • I've tried that and the quotes around \n also show up in the new csv. Commented Apr 13, 2018 at 12:45
  • Are we really discussing how to add a newline to the file now? Just add file.write('\n'). Commented Apr 13, 2018 at 13:32
  • @Aran-Fey That actually has solved the issue. Thanks Commented Apr 13, 2018 at 14:48

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.