-->

Data File Handling

Question
CBSEENCO12011549

Considering the following definition of class COMPANY, write a method in Python to search and display the content in a pickled file COMPANY.DAT, where CompID is matching with the value ‘1005’.

class Company:
	def __init__(self,CID,NAM):
	self.CompID = CID 	#CompID Company ID
	self.CName = NAM 	#CName Company Name
	self.Turnover = 1000
	
	def Display(self):
		print self.CompID,':',self.CName,':',self.Turnover

Solution
import pickle
def ques4c():
	f=Factory()
	file=open('COMPANY.DAT','rb')
	try:
		while True:
			f=pickle.load(file)
			if f.CompID==1005:
				f.Display()
			except EOF Error:
				pass
	file.close() #IGNORE

Some More Questions From Data File Handling Chapter