We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ee0d637 commit 9c54b37Copy full SHA for 9c54b37
1 file changed
1 File handle/File handle binary/update2.py
@@ -1,10 +1,14 @@
1
# Updating records in a binary file
2
# ! Have a .env file please
3
import pickle
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")
9
10
def update():
- with open("class.dat", "rb+") as F:
11
+ with open(student_record, "rb") as F:
12
S = pickle.load(F)
13
found = False
14
rno = int(input("enter the roll number you want to update"))
@@ -19,12 +23,9 @@ def update():
19
23
if found:
20
24
print("Record not found")
21
25
22
- else:
- F.seek(0)
- pickle.dump(S, F)
26
27
+ with open(student_record, "wb") as F:
28
+ pickle.dump(S, F)
29
-update()
30
-with open("class.dat", "rb") as F:
- print(pickle.load(F))
31
+update()
0 commit comments