This is the data my file:
- John Smith, 5
- Luke Smith, 7
- Mary Smith, 8
- Boby Smith, 2
I want to be able to add another number onto a specific user in the file. See below (Mary).
- John Smith, 5
- Luke Smith, 7
- Mary Smith, 8, 6
- Boby Smith, 2
My code:
with open('filename.txt','a') as file:
file.write("\n{}, {}".format(name,number))
This code will append/write to the file just fine, but it writes in new users each time, which I do not want it to do. I want it to check to see if a user is already in the file, and append that line with the new number. If user does not already exist, add them to the file.