How can I insert alternative empty rows into a table with Python?

I have a simple (but huge) CSV table, and I need to insert a free (= empty) row / row after each row / row of this table. To explain this differently, I want every second row of my table to be empty (but without deleting / overwriting any of the original rows). I tried many ways, but this is the best I could come up with:

with open(sys.argv[1], 'r') as input:
   readie=csv.reader(input, delimiter=',')
   with open("output.csv", 'wt', newline='') as output:
       outwriter=csv.writer(output, delimiter=',')
       for row in readie:
           row_plus = (row, \n)
           outwriter.writerow(row_plus)

It does not work, because it fills all the columns of the table into one column and interprets (row, \n)only as two columns. It also just prints "\ n" and does not recognize that I want it to insert another line break.

+3
source share
1 answer

What about:

  for row in readie:
     outwriter.writerow(row)
     outwriter.writerow([])

, , .

+6

All Articles