My program is a basic Tkinter game with a scoreboard type system. This system stores the username and the number of attempts each user has had in a text file.
For example, when it is the user's first time, it appends their name to the end of the text file as [joe_bloggs, 1] with joe_bloggs being the username and 1 being the number of attempts. As its the user's first time, it's 1.
I am trying to look for a way to 'update' or change the number '1' to increment by 1 each time. This text file stores all the users, i.e [Joe,1] [example1, 1] [example2, 2] in that format.
Here is the code I currently have:
write = ("[", username, attempts ,"]") if (username not in filecontents): #Searches the file contents for the username with open("test.txt", "a") as Attempts: Attempts.write(write) print("written to file") else: print("already exists") #Here is where I want to have the mechanism to update the number. Thanks in advance.