Module for reading CSV data

Cliff Wells logiplexsoftware at earthlink.net
Fri Nov 9 15:33:48 EST 2001


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.

Here's another approach using zip() which may be faster (don't really have 
enough data to benchmark):

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

d = {}

key = 0
for data in apply(zip, l[1:]):
    d[l[0][key]] = data
    key += 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