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

Gora Mohanty gora at mimirtech.com
Mon Jul 28 20:09:57 CEST 2014

On 28 July 2014 21:49, VIMAL K <vimal.k at ieee.org> wrote:
> Hello,
> 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:

What do you mean by "datastore" in this context?

> 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():
>                     columns[k].append(v)
>         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

Would you be kind enough to explain how this code snippet relates to
the description
of what you wanted the code to do? It seems to be cut-and-pasted from somewhere
else, and I cannot see how it is relevant. What in the world is "CallLog"?


More information about the BangPypers mailing list