Skip to content

Commit 9c54b37

Browse files
add .env fix runtime errors
1 parent ee0d637 commit 9c54b37

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Updating records in a binary file
22
# ! Have a .env file please
33
import pickle
4-
4+
import os
5+
from dotenv import load_dotenv
6+
base = os.path.dirname(__file__)
7+
load_dotenv(os.path.join(base, ".env"))
8+
student_record = os.getenv("STUDENTS_RECORD_FILE")
59

610
def update():
7-
with open("class.dat", "rb+") as F:
11+
with open(student_record, "rb") as F:
812
S = pickle.load(F)
913
found = False
1014
rno = int(input("enter the roll number you want to update"))
@@ -19,12 +23,9 @@ def update():
1923
if found:
2024
print("Record not found")
2125

22-
else:
23-
F.seek(0)
24-
pickle.dump(S, F)
2526

27+
with open(student_record, "wb") as F:
28+
pickle.dump(S, F)
2629

27-
update()
2830

29-
with open("class.dat", "rb") as F:
30-
print(pickle.load(F))
31+
update()

0 commit comments

Comments
 (0)