File Handling Using Python Programming Practice Series-II With Answers
File Handling Using Python Programming Practice Series-II With Answers
A writerow() B writelines()
C writerows() D writeline()
E writeln()
3. 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: line 1: pickle, line 5: f,dump(rec1), line
C D
f.writerecord(rec2,f) 6: f.dump(rec2)
4. To open a file poem.txt for reading, the correct syntax is___________
A f=('poem.txt','w') B file=open(file='poem.txt','r')
C fileopen=('poem.txt','r') D file=open('poem.txt','r')
A salesdet_reader=csvreader.fh B salesdet_reader=csvreader(fh)
C salesdet_reader=csv.read(fh) D salesdet_reader=csv.reader(fh)
6. Function readline() and readlines() are both the same functions. Is the statement
True or False
A False B True
7. To read 18 characters from the file object fobj , the correct syntax is
____________.
A fobj.readline(18) B fobj.readlines(18)
C fobj.readchar(18) D fobj.read(18)
A filter B colon
C tab D comma
11. To read the entire contents of a text file as a string from a file object fobj , the
correct syntax is _____________
A fobj.readlines() B fobj.read()
C fobj.readline(18) D fobj.read(all)
A writelines() B writerow()
C writerows() D writerecords()
13. The __________ function changes the position of the file pointer by placing the file
pointer at the specified position in an open file
A loc B seek()
C pos() D tell()
14. CSV files are known as flat text files. Is the statement true or false.
A False B True
15. ______________ is the process of converting Python object hierarchy into a byte
stream so that it can be written to a file
A Translation B Conversion
C unpickling D Serialization
16. The __________ function returns the current position of file pointer in the file.
A pos() B loc
C seek() D tell()
17. _________________ and __________ are the two objects associated with the csv
module to read and write onto a CSV file.
18. _____ function will break the link of file object and file on the disk
A close() B read()
C open() D write()
first read the file and then write the first write the file by deleting the
A contents by deleting its contents, if B contents of the existing file, if the file
the file exists. exists.
first write and then read the file first read and then write the contents,
C contents, by deleting the contents of D by deleting the contents of the file if
the file if the file exists. the file exists.
20. _____ function without any argument removes leading and trailing whitespaces.
A strip() B rstrip()
C lstrip() D trim()
Answer Key
1. b 2. c 3. b 4. d
5. d 6. a 7. d 8. d