NEW
Font size
WorksheetsFile Handling Revision- Text file Handling Quiz 1
Total questions: 20
Worksheet time: 3mins
To open a file poem.txt for reading, the correct syntax is___________
file=open('poem.txt','r')
file=open(file='poem.txt','r')
fileopen=('poem.txt','r')
f=('poem.txt','w')
To read the entire contents of a text file as a string from a file object fobj , the correct syntax is _____________
fobj.read()
fobj.read(all)
fobj.readlines()
fobj.readline(18)
To read 18 characters from the file object fobj , the correct syntax is ____________.
fobj.readlines(18)
fobj.readchar(18)
fobj.read(18)
fobj.readline(18)
Mention the data type of variable check in the following statements?
a. check=f.read()
b. check=f.readline()
c. check=f.readlines()
a. str b. str c. list
a. list b. str c. list
a. str b. list c. list
a. str b. list c. str
'w+' mode will _________________
first write the file by deleting the contents of the existing file, if the file exists.
first read the file and then write the contents by deleting its contents, if the file exists.
first write and then read the file contents, by deleting the contents of the file if the file exists.
first read and then write the contents, by deleting the contents of the file if the file exists.
_____ function will break the link of file object and file on the disk
open()
read()
write()
close()
_____ function without any argument removes leading and trailing whitespaces.
strip()
lstrip()
rstrip()
trim()
______________ is the process of converting Python object hierarchy into a byte stream so that it can be written to a file
Conversion
Translation
Serialization
unpickling
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
line 1: csv, line 5: f.write(rec1) , line 6: f.writerecord(rec2,f)
line 1: pickle, line 5: f.dump(rec1) , line 6: f.dump(rec2,f)
line 1: pickle, line 5: f,dump(rec1), line 6: f.dump(rec2)
line 1: pickle, line 5: pickle.dump(rec1,f) , line 6: pickle.dump(rec2,f)
The __________ function returns the current position of file pointer in the file.
tell()
loc
seek()
pos()
The __________ function changes the position of the file pointer by placing the file pointer at the specified position in an open file
tell()
loc
seek()
pos()
The default delimiter of the CSV file is ____________.
tab
comma
colon
filter
To create a csv file sales.csv, the correct syntax is _____________
f=open('sales.csv', 'w')
f=open('sales.csv', 'r')
f=open('sales.csv', 'w+')
f=open('sales.csv', 'a')
_________________ and __________ are the two objects associated with the csv module to reading and write onto a CSV file.
reader() and writer()
read() and write()
dump() and load()
write() and writelines()
_________________ and __________ are the two objects associated with the csv module to read and write onto a CSV file.
reader() and writer()
read() and write()
dump() and load()
write() and writelines()
_________________ function is used to write single row at a time.
writerow()
writerows()
writerecords()
writelines()
_________________ method writes all given rows to the csv file.
writerow()
writerows()
writeln()
writelines()
writeline()
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.
salesdet_reader=csv.reader(fh)
salesdet_reader=csvreader(fh)
salesdet_reader=csv.read(fh)
salesdet_reader=csvreader.fh
Function readline() and readlines() are both the same functions. Is the statement True or False
True
False
CSV files are known as flat text files. Is the statement true or false.
True
False
