Im having a hard time trying to delete empty(blank) rows from a csv file using python 3.4.3. Each time I run my script the output remains the same as the original.
import csv
...
with open('demo004.csv') as input, open('demo005.csv', 'w') as output:
writer = csv.writer(output)
for row in csv.reader(input):
if any(field.strip() for field in row):
writer.writerow(row)
input.close()
output.close()
My CSV file is in the format.
AA,AB,AC
BA,BB,BC
CA,CB,CB
Whereas I would like to obtain
AA,AB,AC
BA,BB,BC
CA,CB,CB
demo004.csvordemo005.csvthat would be helpfulwithstatement) would be causing exceptionswith, and it looks like you removed the colon you need at the end of the line. Start with your original code (which works for me) and simply addnewline=''inside both opens.