DictReader and fieldnames

skip at pobox.com skip at pobox.com
Thu Mar 19 15:32:01 EDT 2009


    Ted> Thanks.  Is there any way to make this work before actually reading
    Ted> in a row of data?  In version 2.5, I need to first do a rdr.next()
    Ted> before rdr.fieldnames gives me anything.

If you know the csv file contains column headers this should work:

    f = open("f.csv", "rb")
    names = csv.reader(f).next()
    rdr = csv.DictReader(f, fieldnames=names)

Skip



More information about the Python-list mailing list