forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdate a binary file2.py
More file actions
40 lines (28 loc) · 1.05 KB
/
Update a binary file2.py
File metadata and controls
40 lines (28 loc) · 1.05 KB
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
33
34
35
36
37
38
39
40
# updating records in a binary file
import pickle
import os
base = os.path.dirname(__file__)
from dotenv import load_dotenv
load_dotenv(os.path.join(base, ".env"))
student_record = os.getenv("STUDENTS_RECORD_FILE")
## ! Understand how pandas works internally
def update():
with open(student_record, "rb") as File:
value = pickle.load(File)
found = False
roll = int(input("Enter the roll number of the record"))
for i in value:
if roll == i[0]:
print(f"current name {i[1]}")
print(f"current marks {i[2]}")
i[1] = input("Enter the new name")
i[2] = int(input("Enter the new marks"))
found = True
if not found:
print("Record not found")
with open(student_record, "wb") as File:
pickle.dump(value, File)
update()
# ! Instead of AB use WB?
# ! It may have memory limits while updating large files but it would be good
# ! Few lakhs records would be fine and wouldn't create any much of a significant issues