Created
January 8, 2013 14:14
-
-
Save EdwardIII/4484071 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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