Q. Consider the following definition of dictionary Staff, write a method in python to search and display the content in a pickled file staff.dat, where Staffcode key of the dictionary is matching with 'S0105'.
Staff = {‘Staff Code': _____, 'Name' = _____}
Answer =
import pickle
file = open("staff.dat", "rb")
found = 0
try :
while True :
staff = pickle.load(file)
if staff [ "Staff Code" ] == 'S0105':
print(staff)
found=1
except EOFError :
if found == 0:
print("Not found !!!")
file.close()
Super
ReplyDeleteThank you : )
DeleteWrong Code
ReplyDeleteWhy ???
DeleteAnswer kaha hai
ReplyDeleteOutput
DeleteQuestion says to read the file.
ReplyDeleteAnswer
ReplyDeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )