How to create a CSV file Dynamically using Feed in python? -


i'm exporting data python csv library works pretty good. after web-search can not find information how dynamically place rows python.

for example.

for table_id in table_ids:     data_query = gdata.analytics.client.datafeedquery({             'ids': table_id,             'start-date': datetime.date(2013, 6, 9),             'end-date': datetime.date(2013, 7, 9),                     'dimensions': 'ga:country',              'metrics': 'ga:visits, ga:visitors'})     feed = client.getdatafeed(data_query) 

i exporting below:

for x2 in feed.entry:     y2 in x2.dimension:         csvout.writerow((y2.value.encode('utf-8'),''))     z2 in x2.metric:           csvout.writerow(('',z2.value.encode('utf-8'))) 

it works 1 metric if want pass 3 metrics, need data in different 3 columns. idea how works?

read in list , append writerow method in csvout. work.

example:

lendim = range(len(i.dimension))

for lend in lendim:

             csvlist.append(i.dimension[lend].name)  

for lenm in lenmet:

             csvlist.append(i.metric[lenm].name)                csvout.writerow(csvlist) 

that's it. it's working fine.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -