How to Get Data from DictReader for CSV Files

GZ zyzhu2000 at gmail.com
Mon Nov 21 11:29:53 EST 2011


Hi,

On Nov 21, 7:42 am, ray <r... at aarden.us> wrote:
> 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.



More information about the Python-list mailing list