Normally that is not done. Because it is not as CSV files are meant to work.
CSV files are loose text files, which can contain variable length free information for each field, provided the number of fields in all lines are the same. But, although they can be specified so, the field lengths themselves are not fixed. In this case, for example, when the score would change from "8" to "10", you would overwrite the next field separator (","), and break the file, if you where using strictly what you want.
Actually, any text file in computing is usually meant as a "source" of information only - and whenever the information change, the usual thing to do is just to re-write the whole file again (and delete the previous version).
That may seem like a waste of resources - but at the Operating System/Hardware level, the minimum ammount of bytes written to disk is usually 4096 at once. It means that even if you manage creating your program to change a single character on disk, recording it will still write back 4000+ bytes to disk.
In a case like this, the most recomended approach are: (1) Recreate the whole file for each change you have - that won't be a problem for up to a few hundred basketball players.
(2) If you have more than a few hundred (or a lot more information than a single score for each player), the best approach is to have an SQL database - and let the database controller take care of addressing the correct cell and most efficiently updating it on disk. Actually, the database approach might be good even with few records. In Python, you can have an sqlite - single file, self contained database - with no configuration and not software install.
(3) It is possible to have a CSV file that reserves, say, 5 digits minimum for each cell, and them using complicated techniques to update just those cell. It won't save computer resources (see above), and will make the maintenance of your program complicated. But it could be great to learn more about programming and how files work - as an exercise.
So - here is how a minimal program using approach (1) would look like:
import csv
import os
player_file = "players.csv"
fieldnames = None
def get_data(playerDocument):
"""
Reads in the whole CSV file as a single dictionary, having the player name as key.
"""
global fieldnames
with open(playerDocument) as inputfile:
reader = csv.DictReader(inputfile)
fieldnames = reader.fieldnames
return {record["Name"]:record for record in reader}
def update_record(data, player_name, amount=2):
data[player_name]["Score"] += amount
def save_data(playerDocument, data):
temp_name = playerDocument + ".temp"
with open(temp_name, "wt") as outputfile:
writer = csv.DictWriter(outputfile)
writer.writeheader(fieldnames)
writer.writerows(sorted(data.values(), key=lambda record: record["Name"]))
os.unlink(playerDocument)
os.rename(temp_name, playerDocument)
def main():
player = input("Player name to update: ")
data = get_data(player_file)
upate_record(data, player)
save_data(player_file)
main()