Module for reading CSV data

Cliff Wells logiplexsoftware at earthlink.net
Fri Nov 9 15:16:43 EST 2001


On Friday 09 November 2001 12:11, Cliff Wells wrote:
> On Friday 09 November 2001 11:20, David A McInnis wrote:
> > Is there a module for reading CSV files into a dictionary?  Or is there a
> > builtin that is used in conjunction with readlines()?
> >
> > The first row of my csv file contains field names.
>

Oops, the code I sent also puts the column name in the data.  This is correct:

l = [
    ['a', 'b', 'c', 'd', 'e'],
    [1, 2, 3, 4, 5],
    [6, 7, 8, 9, 10],
]

d = {}

for h in range(len(l[0])):
    d[l[0][h]] = [row[h] for row in l[1:]]

-- 
Cliff Wells
Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308
(800) 735-0555 x308




More information about the Python-list mailing list