on-internet
← Community

create new column of values against an existing string in a csv file in python [duplicate]

Stack Overflow ·

I have a program to store a persons name and their score, in a csv file in python. for example this is my current code : student_name = input("Name: ") score = input("Score: ") class_name = "student_scores.csv" file = open(class_name , 'a') file.write(str(student_name) + ", " + str(score) + "\n") file.close() The output csv file is, (name = bob) and (score = 1) : bob, 1 When i enter another score (2) for the same person (bob) the csv file looks like this: bob, 1 bob, 2 However how can i change my code, so that the csv file looks like this (with more than 2 columns) : bob, 1, 2

Comments

Sign in or sign up to comment and upvote.

No comments yet.