Class 12 : File Handling Set 4

16.
Read the code given below and answer the question:
fh=open(“temp.txt”,”w”)
fh.write(“Bye”)
fh.close()
If the file contains “GOOD” before execution, what will be the contents of the file after execution of this code?

17.
What will be the output of the following code?

import pickle
	names=['first','second','third','fourth','fifth']
	lst=[]
	for i in range(-1,-5,-1):
	lst.append(names[i])
	with open('text.dat','wb') as f:
		pickle.dump(lst,f)
	with open('text.dat','rb') as f:
		nlist= pickle.load(f)
	print(nlist)

 

18.
Your recipe uses some ingredients. write a program to store the list of ingredients in a binary file.

19.
Write a program to increase the salary by Rs. 2000/- of the employee having empno 1251 in the file empl.dat.

20.
Consider the following definition of dictionary Multiplex, write a function in python to search and display all the contents in a pickled file cinema.dat, where Mtype key of the dictionary is matching with the value ‘Comedy’.
Mutliplex={‘Mno’:……,’Mname’:………, ‘Mtype’:…….}