import csv
with open('scores.csv') as handle:
reader = csv.reader(handle)
for row in list(reader)[1:]:
user, *scores = row
average = sum([int(score) for score in scores]) / len(scores)
print (
"{user} has average of {average}".format(user=user,average=average)
)
Run Code Online (Sandbox Code Playgroud)
由于*分数,此代码在python 2.7中不起作用.我如何将其更改为python 2.7,因为我不知道如何?
此代码取自此主题:行平均CSV Python