Thursday 15 July 2010

python - CSV readinf TypeError: 'int' object is not iterable -



python - CSV readinf TypeError: 'int' object is not iterable -

python newbie here. maintain getting error when trying sort csv list

i have code write csv file works ok in writes name , 3 scores e.g. john, 3,2,2,

f = open('test.csv', "a") try: author = csv.writer(f) writer.writerow( (name, myscore, myscore2, myscore3) ) print("your entries have been added") finally: f.close()

but want read csv , sort output

sample = open('test.csv','r') test1 = csv.reader(sample,delimiter=',', quotechar='|') sort = sorted(test, key=operator.itemgetter(0)) row in sort: print (row)

tried itemgetter(1)), 2,3 etc.. same int object not iterable error? missing obvious (not me!) can help me work out. thanks.

python csv

No comments:

Post a Comment