[Tutor] Program gets stuck after a creating a list from dictinary items!

Ali Torkamani torkamani at gmail.com
Fri Jul 6 17:47:58 CEST 2012


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()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120706/9c54b379/attachment.html>


More information about the Tutor mailing list