+ 1

User IDs not being updated in binary file (python)

**Aim:** Creating a binary file with Student ID, name and User ID. Taking a student ID as input from and updating the user ID. So I created the file: #creating the file import pickle data=[[12, "Hook", 97], [45, "Lola", 65], [34, "Maya", 99], [79, "Lumberjill", 100]] with open("sheets.dat","wb") as m: for i in data: pickle.dump(i,m) Reading the contents before update: #reading file contents m=open("sheets.dat", "rb") try: while 1: j=pickle.load(m) print(j) except EOFError: m.close() **Output:** [12, 'Hook', 97] [45, 'Lola', 65] [34, 'Maya', 99] [79, 'Lumberjill', 100] Updating the User ID: #update on marks m=open("sheets.dat", "rb+") roll=int(input("Enter SID:")) try: while 1: pos=m.tell() j=pickle.load(m) if j[0]==roll: marks=int(input("Enter updated UID:")) j[2]==marks m.seek(pos) pickle.dump(j,m) except EOFError: m.close() However, after the update (Tried to change Lumberjill's UID to 54): [12, 'Hook', 97] [45, 'Lola', 65] [34, 'Maya', 99] [79, 'Lumberjill', 100] Nothing's really changed. Now, where did I mess up?

3rd Dec 2022, 2:00 PM
MsBonnie
MsBonnie - avatar
1 Respuesta
0
May be indentantion in line : except EOFError update
7th Dec 2022, 8:27 PM
Václav Dostál
Václav Dostál - avatar