File tree Expand file tree Collapse file tree 1 file changed +29
-8
lines changed
1 File handle/File handle binary Expand file tree Collapse file tree 1 file changed +29
-8
lines changed Original file line number Diff line number Diff line change 11import pickle
2+ import os
3+ import logging
24
5+ logging .basicConfig (level = logging .INFO , format = '%(levelname)s: %(message)s' )
36
4- def bdelete ():
7+
8+ def b_read ():
59 # Opening a file & loading it
6- with open ("studrec.dat" , "rb" ) as F :
7- stud = pickle .load (F )
8- print (stud )
10+ if not os .path .exists ("student_records.pkl" ):
11+ logging .warning ("File not found" )
12+ return
13+
14+ with open ("student_records.pkl" , "rb" ) as F :
15+ student = pickle .load (F )
16+ logging .info ("File opened successfully" )
17+ logging .info ("Records in the file are:" )
18+ for i in student :
19+ logging .info (i )
920
21+ def b_modify ():
1022 # Deleting the Roll no. entered by user
11- rno = int (input ("Enter the Roll no. to be deleted: " ))
12- with open ("studrec.dat" , "wb" ) as F :
13- rec = [i for i in stud if i [0 ] != rno ]
23+ if not os .path .exists ("student_records.pkl" ):
24+ logging .warning ("File not found" )
25+ return
26+ roll_no = int (input ("Enter the Roll No. to be deleted: " ))
27+ student = 0
28+ with open ("student_records.pkl" , "rb" ) as F :
29+ student = pickle .load (F )
30+
31+ with open ("student_records.pkl" , "wb" ) as F :
32+ rec = [i for i in student if i [0 ] != roll_no ]
1433 pickle .dump (rec , F )
1534
1635
17- bdelete ()
36+
37+ b_read ()
38+ b_modify ()
You can’t perform that action at this time.
0 commit comments