[go: up one dir, main page]

0% found this document useful (0 votes)
9 views4 pages

Xii MCQ Data File

Uploaded by

spidermandie1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Xii MCQ Data File

Uploaded by

spidermandie1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

MCQ ON FILE HANDLING

1. To open a file c:\scores.txt for reading, we use _____________


a) infile = open(“c:\scores.txt”, “r”)
b) infile = open(“c:\\scores.txt”, “r”)
c) infile = open(file = “c:\scores.txt”, “r”)
d) infile = open(file = “c:\\scores.txt”, “r”)

2. To open a file c:\scores.txt for writing, we use ____________


a) outfile = open(“c:\scores.txt”, “w”)
b) outfile = open(“c:\\scores.txt”, “w”)
c) outfile = open(file = “c:\scores.txt”, “w”)
d) outfile = open(file = “c:\\scores.txt”, “w”)

3. To open a file c:\scores.txt for appending data, we use ____________


a) outfile = open(“c:\\scores.txt”, “a”)
b) outfile = open(“c:\\scores.txt”, “rw”)
c) outfile = open(file = “c:\scores.txt”, “w”)
d) outfile = open(file = “c:\\scores.txt”, “w”)

4. Which of the following statements are true?


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 mentioned

5. To read two characters from a file object infile, we use ____________


a) infile.read(2)
b) infile.read()
c) infile.readline()
d) infile.readlines()

6. To read the entire remaining contents of the file as a string from a file object infile, we use
____________
a) infile.read(2)
b) infile.read()
c) infile.readline()
d) infile.readlines()

7. To read the next line of the file from a file object infile, we use ____________
a) infile.read(2)
b) infile.read()
c) infile.readline() correct
d) infile.readlines()

8. To read the remaining lines of the file from a file object infile, we use ____________
a) infile.read(2)
b) infile.read()
c) infile.readline()
d) infile.readlines()

9. The readlines() method returns ____________


a) str
b) a list of lines
c) a list of single characters
d) a list of integers
10. What is the use of tell() method in python?
a) tells you the current position within the file
b) tells you the end position within the file
c) tells you the file is opened or not
d) none of the mentioned

11. What will be the output of the following Python code?


fo = open("foo.txt", "rw+")
print( "Name of the file: ", fo.name)
a) Compilation Error
b) Syntax Error
c) Displays Output
d) None of the mentioned

12. What is the use of seek() method in files?


a) sets the file’s current position at the offset
b) sets the file’s previous position at the offset
c) sets the file’s current position within the file
d) none of the mentioned

13. Which of the following mode will refer to binary data?


a) r
b) w
c) +
d) b

14. What is the pickling?


a) It is used for object serialization
b) It is used for object deserialization
c) None of the mentioned
d) All of the mentioned

15. What is unpickling?


a) It is used for object serialization
b) It is used for object deserialization
c) None of the mentioned
d) All of the mentioned

16. What is the correct syntax of open() function?


a) file = open(file_name [, access_mode][, buffering])
b) file object = open(file_name [, access_mode][, buffering])
c) file object = open(file_name)
d) None of the mentioned

17. Correct syntax of file.writelines() is?


a) file.writelines(sequence)
b) fileObject.writelines()
c) fileObject.writelines(sequence)
d) none of the mentioned

18. Correct syntax of file.readlines() is?


a) fileObject.readlines( sizehint );
b) fileObject.readlines();
c) fileObject.readlines(sequence)
d) None of the mentioned
19. What does the <readlines()> method returns?
A. str
B. a list of lines
C. list of single characters
D. list of integers

20. Which of the following functions do you use to write data in the binary format?
A. write
B. output
C. dump
D. send

21. Which function is used to read all the characters?


a.Read()
b.Readcharacters()
c.Readall()
d.Readchar()

22. Which function is used to write a list of string in a file


a.writeline()
b.writelines()
c.writestatement()
d.writefullline()

23. Which of the following is modes of both writing and reading in binary format in file.?
a.wb+
b.w
c.wb
d.w+

24. Which of the following is not a valid mode to open a file?


a.ab
b.rw
c.r+
d.w+

25. What is the difference between r+ and w+ modes?


a.no difference
b.in r+ the pointer is initially placed at the beginning of the file and the pointer is at the end for w+
c.in w+ 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

26. How do you get the name of a file from a file object (fp)?
a.fp.name
b.fp.file(name)
c.self.__name__(fp)
d.fp.__name__()

27. How do you close a file object (fp)?


a.27.fp)
b.fclose(fp)
c.fp.close()
d.fp.__close__()

28.How do you get the current position within the file?


a.fp.seek()
b.fp.tell()
c.fp.loc
d.fp.pos

29.How do you change the file position to an offset value from the start?
a.fp.seek(offset, 0)
b.fp.seek(offset, 1)
c.fp.seek(offset, 2)
d.none of the mentioned

30.What happens if no arguments are passed to the seek function?


a.file position is set to the start of file
b.file position is set to the end of file
c.file position remains unchanged
d.error

You might also like