Python has a fancy CSV
module. But near as I can tell, despite all its support for
formats and headers and DictReaders it doesn't have a simple way to
say "give me my data in a list of dictionaries with headers as keys".
Here's the best I could do:
# Grab the headers first headerReader = csv.reader(fp) headers = headerReader.next() # Now construct a second reader on the same # file stream to get the actual data dataReader = csv.DictReader(fp, headers) for d in dataReader: print dThat feels spooky, but it works. |