File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed
1 File handle/File handle binary Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change 11# Updating records in a binary file
22# ! Have a .env file please
33import 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
610def 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 ()
You can’t perform that action at this time.
0 commit comments