python - Writing headers in CSV file -
i have programme run on cron job , write output csv file.
i write correctly create programme write headers on first row when file created. there way of programme checking if there rows in csv file and, if not, writing headers.
just utilize flag:
headers_written = false
then when writing rows:
if not headers_written: writer.writerow(headers) headers_written = true writer.writerow(somerow)
you'd postpone creating author until sure have stuff write:
writer = none # ... if not writer: author = csv.writer(open(filename, 'wb')) writer.writerow(headers) writer.writerow(somerow)
python csv
No comments:
Post a Comment