From 2f04f474275fdf6bca32aaa1f3fcbf97cc8e50c2 Mon Sep 17 00:00:00 2001 From: DarkCodeOrg Date: Fri, 13 Aug 2021 15:28:08 +0530 Subject: [PATCH] foobar --- file_handling_3.py | 25 ++++++++++++++++++------- student_new.dat | Bin 101 -> 152 bytes 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/file_handling_3.py b/file_handling_3.py index 32a0a9c..1808991 100644 --- a/file_handling_3.py +++ b/file_handling_3.py @@ -22,18 +22,29 @@ # Creating / opening / closing binary files # -dfile = open("student_new.dat","ab") # b specifies to open it in binary mode -data = {} ## creating an empty dictionary +dfile = open("student_new.dat","rb+") # b specifies to open it in binary mode +data_w = {} ## creating an empty dictionary for writing purpose +data_r = {} ## creating an empty dictionary for reading purpose + ## reading the file +try : + print("file student_new.dat conains the following records :") + while True: ## sets to false if end of file is encountered + data_r = pickle.load(dfile) + print(data_r) +except EOFError: + dfile.close() + +dfile = open("student_new.dat","ab+") No_of_stdnt = int(input("enter the no of students in class :")) for i in range(No_of_stdnt): name = input("Enter the name of the student :") roll = int(input("enter the roll no of the student :")) marks = int(input("eneter the marks obtained by the student :")) - data['Name'] = name - data['Roll'] = roll - data['Marks'] = marks - ## the above three lines fillup the dictionary - pickle.dump(data,dfile) + data_w['Name'] = name + data_w[ 'Roll'] = roll + data_w[ 'Marks'] = marks + ## thedata_r above three lines fillup the dictionary + pickle.dump(data_w,dfile) dfile.close() diff --git a/student_new.dat b/student_new.dat index e71a9cb1b3c3bcb256b9b93de797d586ce7b3947..eb078dc6cb8d3ce4acc54698d6c44b6c68c9e343 100644 GIT binary patch delta 40 wcmYeD!8k!eBEK{@aY_$MP<~F%6mQiYR^P;;?BXfD<`WG}C+M@BU@X-G041vp{r~^~ delta 13 UcmbQim^wjXVy!sivWW(!03ZScX#fBK