Professional Documents
Culture Documents
File Handling Mcqs 1. To Open A File C:/test - TXT For Reading, We Should Give The
File Handling Mcqs 1. To Open A File C:/test - TXT For Reading, We Should Give The
(a) When you open a file for reading, if the file does not exist,
an error occurs.
(b) When you open a file for writing, if the file does not exist, a
new file is created.
(c) When you open a file for writing, if the file exists, the
existing file is overwritten with the new file.
(d) All of the above.
(a) fobj.read(2)
(b) fobj.read()
(c) fobj.readline()
(d) fobj.readlines()
(a) fobj.read(2)
(b) fobj.read()
(c) fobj.readline()
(d) fobj.readlines()
f = None
for i in range (5):
with open ("data.txt", "W") as f:
if i > 2:
break
print (f.closed)
(a) True
(b) False
(c) None
(d) Error
8. To read the next line of the file from a file object fobj, we
use:
(a) fobj.read(2)
(b) fobj.read()
(c) fobj.readline()
(d) fobj.readlines()
9. To read the remaining lines of the file from a file object fobj,
we use:
(a) fobj.read(2)
(b) fobj.read()
(c) fobj.readline()
(d) fobj.readlines
(a) String
(b) A list of integers
(c) A list of single characters
(d) A list of lines
11. Which module is required to use the built-in function
dump( )?
(a) math
(b) flush
(c) pickle
(d) unpickle
(a) write
(b) output
(c) dump
(d) send
(a) file.writelines(sequence)
(b) fobj.writelines()
(c) fobj.writelines(sequence)
(d) fobj.writeline()
15. In file handling, what do the terms "r" and "a" stand for?
(a) ab
(b) rw
(c) r+
(d) w+
(a) fp.seek(offset, 0)
(b) fp.seek(offset, 1)
(c) fp.seek(offset, 2)
(d) None of the above
(a) No difference
(b) In r+ mode, the pointer is initially placed at the beginning
of the file and the pointer is at the end for w+
(c) In w+ mode, the pointer is initially placed at the beginning
of the file and the pointer is at the end for r+
(d) Depends on the operating system
19. What does CSV stand for?
(a) random
(b) statistics
(c) csv
(d) math
21. Which of the following modes is used for both writing and
reading from a binary file?
(a) wb+
(b) w
(c) wb
(d) w+
(a) fp.seek()
(b) fp.tell()
(c) fp.loc
(d) fp.pos
(a) writer()
(b) append()
(c) reader()
(d) list()
(a) array
(b) dictionary
(c) file
(d) tuple
29. To read the next line of the file from a file object infi, we
use
(a) infi.read(all)
(b) infi.read()
(c) infi.readline()
(d) infi.readlines()
30. To read the remaining lines of the file from a file object infi,
we use
(a) infi.read(all)
(b) infi.read()
(c) infi.readline()
(d) infi.readlines()
(a) str
(b) a list of lines
(c) a list of single characters
(d) a list of integers
(a) r
(b) w
(c) +
(d) b
33. In file handling, what does this term means "r, a"?
(a) read()
(b) read characters()
(c) readall()
(d) readchar()
(a) readline()
(b) readlines()
(c) readstatement( )
(d) readfulline()
(a) write()
(b) writecharacters()
(c) writeall()
(d) writechar()
(a) writeline()
(b) writelines()
(c) writestatement()
(d) writefullline()
(a) wb+
(b) w
(c) wb
(d) w+
(a) ab
(b) rw
(c) r+
(d) w+
(a) No difference.
(b) In r+ mode, the pointer is initially placed at the beginning
of the file and for w+, the pointer is placed at the end.
(c) In w+ mode, the pointer is initially placed at the beginning
of the file and for r+, the pointer is placed at the end.
(d) Depends on the operating system.
2. The open()
_____ function creates a file object used to call other
support methods associated with it.
5. The close()
_____ method of a file object flushes any unwritten
information and closes the file object.
rename()
7. The_____ method is used to rename the file or folder.
remove()
8. The _____ method is used to remove/delete a file.
9. A _____
binary file is a series of 1's and 0's, treated as raw data and
read byte-by-byte.
13. The readlines() returns a list of lines from the file till _____.
ending
18. _____
dump method of pickle module is used to write an object
into binary file.
19. _____
load method of pickle module is used to read data from a
binary file.
import csv
20. _____ statement is given for importing csv module into
your program.
21. _____
join is a string method that joins all values of each row
with comma separator in CSV.
22. _____ object contains the number of the current line in a
CSV file.
23. To end all the file contents in the form of a list, _____
method may be used.
readlines
24. To read all the file contents, _____ method is used.
text
28. The two types of data files can be _____ files and _____
binary files.
TRUE OR FALSE
6. A close() function breaks the link of the file object and the file on
the disk. true
7. When you open a file in read mode, the given file must exist in
the folder, otherwise Python will raise FileNotFound error. true
15. with statement ensures that all the resources allocated to the
file objects get deallocated automatically.
16. CSV module can handle CSV files correctly regardless of the
operating system on which the files were created.
17. CSV module gets automatically imported into your program for
reading a CSV file. false
18. The type of operation that can be performed on a file depends
upon the file mode in which it is opened. true
19. Functions readline() and readlines() are essentially the same. false
20. Every record in a CSV file is stored in reader object in the form
of a list. true
23. tell() method of Python tells us the current position within the
file. true
26. When you open a file for reading, if the file does not exist, an
error occurs. true
27. When you open a file for writing, if the file does not exist, an
error occurs. false
28. When you open a file for writing, if the file exists, the existing
file is overwritten with the new file. true
29. The absolute paths are from the topmost level of the directory
structure.
31. The relative path for a file always remains same even after
changing the directory.
32. The types of operations that can be carried out on a file depends
upon the file mode a file is opened in. true
33. If no path is given with a file name in the file open(), then the
file must exist in current directory.
34. Functions readline() and readlines() are essentially the same. false
35. Python automatically flushes the file buffers before closing a file
with close() function. true