Dear Tutors, I'm trying to write a dictionary into a csv file, in the following code FlatData is the global dictionary whose keys are datetime objects, and the values are list of dictionaries. sCommonFeatures are key's that exist in all of such 'sub'-dictionaries, and sOtherFeatures are the key's that are in some of sub-dictionaries.
The problem is that in line : D=[prog[key1] for key1 in sCommonFeatures] (line 10 below), the program stucks! I appreciate any help. def WriteOneDayToCSV(sCommonFeatures,sOtherFeatures,date): FD=FlatData[date] A=['UniqeDate','Year','Month','Day']+list(sCommonFeatures)+list(sOtherFeatures) pdb.set_trace() with open(str(date.year)+"_"+str(date.month)+"_"+str(date.day)+".csv",'wb') as myfile: fout = csv.writer(myfile, delimiter=',', quotechar="'") fout.writerow(A) for prog in FD: D=[prog[key1] for key1 in sCommonFeatures] print(prog) pdb.set_trace() diff=sOtherFeatures.difference(prog.keys()) prog.update({x:'NONE' for x in diff}) C=[prog[key2] for key2 in sOtherFeatures] A=["%4d%02d%02d" %(date.year,date.month,date.day),date.year,date.month,date.day] fout.writerow(A+D+C) pdb.set_trace() myfile.flush() myfile.close()
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor