-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Expand file tree
/
Copy pathupdate2.py
More file actions
32 lines (24 loc) · 770 Bytes
/
update2.py
File metadata and controls
32 lines (24 loc) · 770 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Updating records in a binary file
# ! Have a .env file please
import pickle
import os
from dotenv import load_dotenv
base = os.path.dirname(__file__)
load_dotenv(os.path.join(base, ".env"))
student_record = os.getenv("STUDENTS_RECORD_FILE")
def update():
with open(student_record, "rb") as F:
S = pickle.load(F)
found = False
rno = int(input("enter the roll number you want to update"))
for i in S:
if rno == i[0]:
print(f"the currrent name is {i[1]}")
i[1] = input("enter the new name")
found = True
break
if found:
print("Record not found")
with open(student_record, "wb") as F:
pickle.dump(S, F)
update()