Chapter Chosen

Data File Handling

Book Chosen

Computer Science With Python

Subject Chosen

Computer and Communication Technology

Book Store

Download books and chapters from book store.
Currently only available for.
CBSE Gujarat Board Haryana Board

Previous Year Papers

Download the PDF Question Papers Free for off line practice and view the Solutions online.
Currently only available for.
Class 10 Class 12

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

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
130 Views

Observe the following table MEMBER carefully and write the name of the RDBMS operation out of (i) SELECTION (ii) PROJECTION (iii) UNION (iv) CARTESIAN PRODUCT, which has been used to produce the output as shown in RESULT. Also, find the Degree and Cardinality of the RESULT.

NO MNAME STREAM
M001 JAYA SCIENCE  
M002 ADIYTA HUMANITIES 
M003 HANSRAJ SCIENCE
M004 SHIVAK COMMERCE

RESULT
NO MNAME  STREAM
M002  ADIYTA HUMANITIES 

SELECTION
Degree of table RESULT=3
Cardinality of table RESULT = 2

96 Views

Write a method in python to read the content from a text file diary.txt line by line and display the same on screen.


def read_file():
	inFile = open('diary.txt', 'r')
	for line in inFile:
		print line
58 Views

Write a method in Python to read lines from a text file DIARY.TXT, and display those lines, which are starting with an alphabet ‘P’.


def display():
	file=open('DIARY.TXT','r')
	line=file.readline()
	while line:
		if line[0]=='P' :
			print line
			line=file.readline()
	file.close() #IGNORE
87 Views

Differentiate between the following:

  1. f = open(‘diary.txt’, ‘r’)
  2. f = open(‘diary.txt’, ‘w’)


  1. diary.txt is opened for reading data.
  2. diary.txt is opened for writing data.
54 Views