CSV reader and unique ids

Mike P michael.pearmain at tangozebra.com
Mon Sep 1 09:32:57 EDT 2008


Hi All,

I'm trying to use the CSV module to read in some data and then use a
hashable method (as there are millions of records) to find unique ids
and push these out to another file,

can anyone advise? Below is the code so far


fin = open(CSV_INPUT, "rb")
fout = open(CSV_OUTPUT, "wb")
reader = csv.reader(fin, delimiter=chr(254))
writer = csv.writer(fout)

headerList = reader.next()
UID = {}

#For help
#print headerList
# ['Time', 'User-ID', 'IP']

try:
     for row in reader[1]:
         UID[row] = 1
     else:
         List= UID.keys()
writer.writerows(List)
fin.close()
fout.close()

Mike



More information about the Python-list mailing list