user6026279
user6026279

Reputation:

fixing code that outputs csv file in python

I need my code to output all the user in the class's score but it only output one user answer a lot of times. Please can you help. Thanks in advance.

filename = class_name + ".csv"

csv.register_dialect('pipes', delimiter='|')

with open(filename, 'a',newline='') as fp:
    a = csv.writer(fp, delimiter=',')
    data=[[name,score]]              
    a.writerow(data)


if get_bool_input("Do you wish to view previous results for your class"):
    with open(filename, 'r') as f:
        reader = csv.reader(f, dialect = 'pipes')
        for row in reader:
            print (data)
else:
    input ("Press any key to exit")

Upvotes: 0

Views: 37

Answers (1)

PM 2Ring
PM 2Ring

Reputation: 55469

You should be doing print(row).

print(data) just prints the last output data list that you wrote.

Upvotes: 3

Related Questions