DictReader and fieldnames

skip at pobox.com skip at pobox.com
Thu Mar 19 12:47:00 EDT 2009


    Ted> Is it possible to grab the fieldnames that the csv DictReader
    Ted> module automatically reads from the first line of the input file?

Like this, perhaps?

    >>> rdr = csv.DictReader(open("f.csv", "rb"))
    >>> rdr.fieldnames
    ['col1', 'col2', 'color']
    >>> rdr.next()
    {'color': '3', 'col2': '2', 'col1': '1'}

-- 
Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/



More information about the Python-list mailing list