Hi everyone,
Ive just got a bit of a problem with a program i am currently writing.
Basically i have got a csv file with a load of flight info in it, i need to parse that and add it to a dictionary so thati can search through it easily.
I ave used the CSV module to open the csv file and i have added the data to a dictionary, but when i print the dictionary, it just shows a load of {}.
This is the first few lines of the csv file:
Origin,Destination,Flight No.,Aircraft ,Days of ,Departure,Arrival ,Begin Date,End Date,
Agartala,Guwahati,CD-7756,ATR,1357,1755,1845,02-Jun-09,----,
Agartala,Guwahati,CD-7756,ATR,246,1850,1945,02-Jun-09,----,
Agartala,Guwahati,CD-7771,ATR,3,0745,0940,03-Jun-09,09-Jun-09,
Agartala,Guwahati,CD-7771,ATR,1,0740,0935,03-Jun-09,09-Jun-09,
Agartala,Guwahati,CD-7771,ATR,3,0740,0935,10-Jun-09,10-Jun-09,
and this is my code so far:
import csv
dicts = []
inputFile = open("ia-schedule.csv", "rb")
parser = csv.reader(inputFile)
firstRec = True
for fields in parser:
if firstRec:
fieldNames = fields
firstRec = False
else:
dicts.append({})
for i,f in enumerate(fields):
dicts[-1][fieldNames[i]] = f
print dicts
any help is very much appreciated.
Thanks
Shaun