In [1]:
import csv
In [2]:
mesa = [
{'first': 'joe', 'last': 'lutz', 'address': 'aqui'},
{'first': 'mike', 'address': 'panera', 'last': 'duncan'},
{'address': 'nashville', 'first': 'travis', 'last': 'cash'},
]
In [3]:
mesa
Out[3]:
In [4]:
columns = ['last', 'first', 'address']
In [5]:
with open('eggs.csv', 'wb') as csvfile:
writer = csv.DictWriter(
csvfile, columns, restval='',
extrasaction='raise', dialect='excel', delimiter='\t')
for row in mesa:
writer.writerow(row)
In [6]:
!ls -l eggs.csv
Would like to have something like following to output the results of a query. Catherine probably knows the canonical example for such for an Oracle database.
In [ ]:
with open('eggs.csv', 'wb') as csvfile:
writer = csv.DictWriter(
csvfile, columns, restval='',
extrasaction='raise', dialect='excel', delimiter='\t')
query_results = do_query(FOO_QUERY_SQL) # This is fakey stub.
for row in query_results:
writer.writerow(row)
In [ ]:
with open('eggs.csv', 'wb') as csvfile:
writer = csv.DictWriter(
csvfile, columns, restval='',
extrasaction='raise', dialect='excel', delimiter='\t')
for row in do_query(FOO_QUERY_SQL): # This is a fakey stub.
writer.writerow(row)
In [ ]:
import psycopg2