i got error while writing data to file

Ben Iannitelli cannedham284 at hotmail.com
Mon Mar 13 13:45:53 EDT 2017


Hello again,

It seems I was a little too quick to hit "send". Option #2 of the two possible solutions I offered is not right. Here's what it should be (unless the formatting gets garbled):

with open('E:/amadown2py-master/reviews1.csv', 'r',encoding='UTF8') as csvfile:
    with open('E:/amadown2py-master/Sam7_pos_rev.txt',mode='wt') as myfile:#Moved this!
        mycsv = csv.reader(csvfile)
        for row in mycsv:
            data = row[0]
            #print (data)
            try:
                score = ast.literal_eval(row[1])
                if score > 3:
                    cnt=0;
                    #print (score)
                    print (data)
                    positivedata.append((data))
                    myfile.writelines('\n'.join(positivedata))
                    #myfile.close()#You shouldn't need this, bc you're using "with"

ttfn,

Ben I.



More information about the Python-list mailing list