I am reading a CSV file called: candidates.csv line by line (row by row) like follows:
import csv
for line in open('candidates.csv'):
csv_row = line.strip().split(',')
check_update(csv_row[7]) #check_update is a function that returns an int
How can I append the data that the check_updates function returns at the end of the line (row) that I am reading? Here is what I have tried:
for line in open('candidates.csv'):
csv_row = line.strip().split(',')
data_to_add = check_update(csv_row[7])
with open('candidates.csv','a') as f:
writer = csv.writer(f)
writer.writerow(data_to_add)
Getting this error:
_csv.Error: iterable expected, not NoneType
Also not entirely sure that this would have added in the right place at the end of the row that I was reading.
Bottom line, how to best add data at the end of the row that I am currently reading?