I want to write the results of a query to a CSV file. I tried the solution from this other SO question: dump csv from sqlalchemy, but got _csv.Error: sequence expected
. Why am I getting this error? How do I correctly write my query results to CSV?
fh = open('data.csv', 'wb')
outcsv = csv.writer(fh)
result = Grant.query.filter(Grant.pi_name==(piname)).all()
for res in result:
outcsv.writerows(res)
fh.close()