How to Get Data from DictReader for CSV Files

R

ray

I don't see how to get my data from the output. I can see the data in
the rows but it is mixed in with the field names. That is, the data I
get comes out as:
fieldname1 : data1 , fieldname2 : data2 , etc.

import csv
linelist=open( "C:/Users/me/line_list_r0.csv", "rb" )
csvReader= csv.DictReader( linelist, dialect='excel' )
for data in csvReader:
print data
linelist.close()

I want to pass this data as arrays or lists to another module such as:
myfunction(data1, data2, data3)

How do I get the data I want out of the pair fieldname1 : data1?

Thanks,
ray
 
G

GZ

Hi,

I don't see how to get my data from the output.  I can see the data in
the rows but it is mixed in with the field names.  That is, the data I
get comes out as:
fieldname1 : data1 , fieldname2 : data2 , etc.

import csv
linelist=open( "C:/Users/me/line_list_r0.csv", "rb" )
csvReader= csv.DictReader( linelist, dialect='excel' )
for data in csvReader:
        print data
linelist.close()

I want to pass this data as arrays or lists to another module such as:
myfunction(data1, data2, data3)

How do I get the data I want out of the pair fieldname1 : data1?

Thanks,
ray

It returns a dict(). You can reference the fields with
data['fieldname1'], etc.
 
R

ray

Hi,

I don't see how to get my data from the output.  I can see the data in
the rows but it is mixed in with the field names.  That is, the data I
get comes out as:
fieldname1 : data1 , fieldname2 : data2 , etc.
import csv
linelist=open( "C:/Users/me/line_list_r0.csv", "rb" )
csvReader= csv.DictReader( linelist, dialect='excel' )
for data in csvReader:
        print data
linelist.close()
I want to pass this data as arrays or lists to another module such as:
myfunction(data1, data2, data3)
How do I get the data I want out of the pair fieldname1 : data1?
Thanks,
ray

It returns a dict(). You can reference the fields with
data['fieldname1'], etc.- Hide quoted text -

- Show quoted text -

GZ,

That works great.

Thanks,
ray
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top