Professional Documents
Culture Documents
Binary File
Binary File
import pickle
file=open("student.dat","wb+")
dict1={}
ans="y"
while ans=="y":
dict1["name"],dict1["roll"]=name,roll
pickle.dump(dict1,file)
file.close()
file=open("student.dat","rb")
found=True
try:
while True:
st=pickle.load(file)
if st["roll"]==a:
found=False
break
except EOFError:
if found==True:
file.close()
output:
Binary file-updating:
import pickle
file=open("student.dat","wb+")
dict1={}
ans="y"
while ans=="y":
dict1["name"],dict1["roll"],dict1["mark"]=name,roll,mark
pickle.dump(dict1,file)
file.close()
file=open("student.dat","rb+")
found=False
try:
while True:
st=pickle.load(file)
if st["roll"]== a:
st["mark"]=mark1
pickle.dump(st,file)
found=True
except EOFError:
if found==True:
print("Changed Successfully")
else: