wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

File Handling Revision- Text file Handling Quiz 1

Total questions: 20

Worksheet time: 3mins

Name
Class
Date
1.

To open a file poem.txt for reading, the correct syntax is___________

a)

file=open('poem.txt','r')

b)

file=open(file='poem.txt','r')

c)

fileopen=('poem.txt','r')

d)

f=('poem.txt','w')

2.

To read the entire contents of a text file as a string from a file object fobj , the correct syntax is _____________

a)

fobj.read()

b)

fobj.read(all)

c)

fobj.readlines()

d)

fobj.readline(18)

3.

To read 18 characters from the file object fobj , the correct syntax is ____________.

a)

fobj.readlines(18)

b)

fobj.readchar(18)

c)

fobj.read(18)

d)

fobj.readline(18)

4.

Mention the data type of variable check in the following statements?

a. check=f.read()

b. check=f.readline()

c. check=f.readlines()

a)

a. str b. str c. list

b)

a. list b. str c. list

c)

a. str b. list c. list

d)

a. str b. list c. str

5.

'w+' mode will _________________

a)

first write the file by deleting the contents of the existing file, if the file exists.

b)

first read the file and then write the contents by deleting its contents, if the file exists.

c)

first write and then read the file contents, by deleting the contents of the file if the file exists.

d)

first read and then write the contents, by deleting the contents of the file if the file exists.

6.

_____ function will break the link of file object and file on the disk

a)

open()

b)

read()

c)

write()

d)

close()

7.

_____ function without any argument removes leading and trailing whitespaces.

a)

strip()

b)

lstrip()

c)

rstrip()

d)

trim()

8.

______________ is the process of converting Python object hierarchy into a byte stream so that it can be written to a file

a)

Conversion

b)

Translation

c)

Serialization

d)

unpickling

9.

Raju created a binary file, student.dat file using the file handle fh. He wants to enter the details of the student into the student.dat file in the form of list. Help him to complete the code.

import ____________ # line 1

f=open('emp.dat','wb') # line 2

rec1=[101,'Sridhar','15 yrs',560] # line 3

rec2=[102,'Sujata','15 yrs',580] # line 4


_____________________________ # line 5

_____________________________ # line 6


f.close() # line 7

a)

line 1: csv, line 5: f.write(rec1) , line 6: f.writerecord(rec2,f)

b)

line 1: pickle, line 5: f.dump(rec1) , line 6: f.dump(rec2,f)

c)

line 1: pickle, line 5: f,dump(rec1), line 6: f.dump(rec2)

d)

line 1: pickle, line 5: pickle.dump(rec1,f) , line 6: pickle.dump(rec2,f)

10.

The __________ function returns the current position of file pointer in the file.

a)

tell()

b)

loc

c)

seek()

d)

pos()

11.

The __________ function changes the position of the file pointer by placing the file pointer at the specified position in an open file

a)

tell()

b)

loc

c)

seek()

d)

pos()

12.

The default delimiter of the CSV file is ____________.

a)

tab

b)

comma

c)

colon

d)

filter

13.

To create a csv file sales.csv, the correct syntax is _____________

a)

f=open('sales.csv', 'w')

b)

f=open('sales.csv', 'r')

c)

f=open('sales.csv', 'w+')

d)

f=open('sales.csv', 'a')

14.

_________________ and __________ are the two objects associated with the csv module to reading and write onto a CSV file.

a)

reader() and writer()

b)

read() and write()

c)

dump() and load()

d)

write() and writelines()

15.

_________________ and __________ are the two objects associated with the csv module to read and write onto a CSV file.

a)

reader() and writer()

b)

read() and write()

c)

dump() and load()

d)

write() and writelines()

16.

_________________ function is used to write single row at a time.

a)

writerow()

b)

writerows()

c)

writerecords()

d)

writelines()

17.

_________________ method writes all given rows to the csv file.

a)

writerow()

b)

writerows()

c)

writeln()

d)

writelines()

e)

writeline()

18.

To create the reader object, the correct syntax is __________.

[Assume that the salesdet.csv file is opened in reading mode in the file handle fh.

a)

salesdet_reader=csv.reader(fh)

b)

salesdet_reader=csvreader(fh)

c)

salesdet_reader=csv.read(fh)

d)

salesdet_reader=csvreader.fh

19.

Function readline() and readlines() are both the same functions. Is the statement True or False

a)

True

b)

False

20.

CSV files are known as flat text files. Is the statement true or false.

a)

True

b)

False