def query_to_csv(cursor, cols, outname):
"""
Turns the query into a CSV file for the GPA calculation.
:param cursor: the database cursor
:type cursor: DictCursor
:param cols: the header names
:type cols: list
:param outname: the CSV output filename
:type outname: str
"""
logger.info("Generating CSV: {0}".format(outname))
with open(outname, 'w') as outfile:
writer = csv.writer(outfile, quoting=csv.QUOTE_NONNUMERIC)
writer.writerow(cols.split(","))
for row in cursor.fetchall():
writer.writerow(row)
outfile.flush()
logger.info("Generated CSV ({0}) exists: ".format(outname, os.path.isfile(outname)))
评论列表
文章目录