Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
19 views

File Handling Using Python Programming Practice Series-II With Answers

The document contains 20 multiple choice questions related to file handling in Python. The questions cover topics like opening and closing files, reading and writing to files, using the CSV module to read and write CSV files, changing the file pointer position, and stripping whitespace from strings. An answer key is provided with the correct response for each question.

Uploaded by

ddivyaguru2006
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

File Handling Using Python Programming Practice Series-II With Answers

The document contains 20 multiple choice questions related to file handling in Python. The questions cover topics like opening and closing files, reading and writing to files, using the CSV module to read and write CSV files, changing the file pointer position, and stripping whitespace from strings. An answer key is provided with the correct response for each question.

Uploaded by

ddivyaguru2006
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

NAME :

File Handling using Python CLASS :


Programming Practice Series-II
DATE :
20 Questions

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

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

C f=open('sales.csv', 'r') D f=open('sales.csv', 'a')

2. _________________ method writes all given rows to the csv file.

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: pickle, line 5: f.dump(rec1) , line 1: pickle, line 5:


A line 6: f.dump(rec2,f) B pickle.dump(rec1,f) , line 6:
pickle.dump(rec2,f)

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')

5. 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=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)

8. The default delimiter of the CSV file is ____________.

A filter B colon

C tab D comma

9. 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. list c. str B a. list b. str c. list

C a. str b. str c. list D a. str b. list c. list


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

A dump() and load() B read() and write()

C write() and writelines() D reader() and writer()

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)

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

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.

A write() and writelines() B dump() and load()

C reader() and writer() D read() and write()

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

A close() B read()

C open() D write()

19. 'w+' mode will _________________

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

9. c 10. d 11. b 12. b

13. b 14. b 15. d 16. d

17. c 18. d 19. c 20. a

You might also like