Skip to content

Instantly share code, notes, and snippets.

@EdwardIII
Created January 8, 2013 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EdwardIII/4484071 to your computer and use it in GitHub Desktop.
Save EdwardIII/4484071 to your computer and use it in GitHub Desktop.
def output_results(results):
if not results:
exit("Couldn't find any results!")
#TODO: use for -v mode
#import os
#for row in results:
# for key in row.keys():
# print '{} {}'.format(key, row[key])
# print os.linesep
if parser.parse_args().output:
out_f = parser.parse_args().output
# Write out header
header = results[0].keys()
# Write out dictionary
import csv
data = csv.DictWriter(out_f, header,delimiter=',')
data.writeheader()
for r in results:
print r
data.writerow(r)
out_f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment