0

My code as below tries to write a list of list into a text file in CSV format,

import csv
villains = [ ['Doctor', 'No','w'], ['Rosa', 'Klebb','w'], ['Mister', 'Big','w'],['Auric', 'Goldfinger','w'],\
            ['Ernst', 'Blofeld','w']]
with open('villains','wt') as fout:
    csvout=csv.writer(fout)
    csvout.writerows(villains)

But I find that if I open the file using Excel (after changing the file name from villains to villains.csv), there are blank lines in between. How do I remove them? BTW, if I change the file name from villains to villains.txt and open with Notepad, I can't spot any blank lines. What happened here?

enter image description here

enter image description here

Nicholas
  • 2,560
  • 2
  • 31
  • 58
  • What happens if you make it add ".csv" to the filename when it makes it? I don't think that'll fix it, but might be worth a shot. – JohnnyFun Jun 25 '16 at 01:39
  • 1
    Oh wait, might be your "mode". Check this: http://stackoverflow.com/questions/3348460/csv-file-written-with-python-has-blank-lines-between-each-row – JohnnyFun Jun 25 '16 at 01:41

0 Answers0