Q. Considering the following definition of dictionary COMPANY, Write a method in Python to search and display the content in a pickled file COMPANY.DAT, where CompID key of the dictionary is matching with the value '1005'.
Company = {'CompID' = ____, 'CName' = ____, ‘Turnover’ = ____}
Answer =
import pickle file = open("COMPANY.DAT","rb") found = 0 try : while True : Company = pickle.load(file) if Company [ "CompID" ] == '1005': print(Company) found=1 except EOFError : if found == 0: print("Not found !!!") file.close()
nice
ReplyDeleteThankyou : )
Deleteyour answers are really vey helpful and you also provide explaination of these questions...so thank you
ReplyDeleteWelcome : )
DeleteShowing file not found
ReplyDeleteat first you have to make COMPANY.DAT file.
Deletecan I have the output
ReplyDeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )