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

Arun Ravindran arunvr at gmail.com
Wed Jul 30 19:56:25 CEST 2014


Hi Vimal,

> I need to write a function which converts a datastore data to csv format,
which is downloadable.

Your code seems to reading a CSV file rather than writing to it. Use a
DictWriter
rather than a DictReader.

But if you need to make it downloadable via a browser, then you need to use
a web framework like Django. Check out the CSV output section
<https://docs.djangoproject.com/en/dev/howto/outputting-csv/> from Django
docs.

Regards,
Arun


On Tue, Jul 29, 2014 at 10:15 AM, HUSSAIN BOHRA <hussainbohra at gmail.com>
wrote:

> I think with datastore, you meant to say 'Google App Engine Datastore'... ?
> If this is the case, please read API details available at:
> https://developers.google.com/appengine/docs/python/datastore/
>
> This would help you extracting data out of datastore.
>
> Thanks,
>
>
>
> On Mon, Jul 28, 2014 at 11:39 PM, Gora Mohanty <gora at mimirtech.com> wrote:
>
> > 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"?
> >
> > Regards,
> > Gora
> > _______________________________________________
> > BangPypers mailing list
> > BangPypers at python.org
> > https://mail.python.org/mailman/listinfo/bangpypers
> >
>
>
>
> --
> Hussain Bohra
> Tavant Technologies
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> https://mail.python.org/mailman/listinfo/bangpypers
>


More information about the BangPypers mailing list