Sponsor Area

Stacks & Queues In List

Question
CBSEENCO12011644

Consider the following definition of class Staff, write a method in python to search and display the content in a pickled file staff.dat, where Staff code is matching with ‘S0105’.

class Staff:

	def __init__(self,S,SNM):
		self.Staffcode=S
		self.Name=SNM
	def Show(self):
		print(self.Staffcode,' ',
			self.Name)

 

Solution
def search():
	f = open(“staff.dat”, ‘rb’)
	try:
		while True:
			e = pickle.load(f)
			if e.Staffcode == ‘S0105’:
				e.Show()
			except EOFError:
				pass
	f.close()