Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions file_handling_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Binary file modified student_new.dat
Binary file not shown.