[BangPypers] How to convert Datastore data into a CSV file python

VIMAL K vimal.k at ieee.org
Mon Jul 28 18:19:28 CEST 2014

i am new to python. I need to write a function which converts a datastore
data to csv format, which is downloadable. I researched upon the topic over
google, got few and less info on it. The code till now is below:

def calllog_csv(self):
        from collections import defaultdict
        date = datetime.strptime('01/01/2014', '%m/%d/%Y')
        qry = CallLog.query().filter(CallLog.created >= date,
CallLog.created <= datetime.now()).fetch()
        columns = defaultdict(qry)
        log.debug("query===>" + str(columns))
        with open('calllog.csv', 'w') as csv_log:
            reader = csv.DictReader(csv_log)
            for row in reader:
                for (k, v) in row.items():
        log.debug("columns== from==>" + str(columns['from']))
        return columns

Tell me where i am wrong, or am i right? any suggestions would be helpfull.
Thank you all in advance

More information about the BangPypers mailing list