WorksheetsQUIZ 22
Total questions: 10
Worksheet time: 5mins
Which of the following command is used to open a file “c:\temp.txt” in read-mode only?
infile = open(“c:\temp.txt”, “r”)
infile = open(“c:\\temp.txt”, “r”)
infile = open(file = “c:\temp.txt”, “r+”)
infile = open(file = “c:\\temp.txt”, “r+”)
Which of the following command is used to open a file “c:\temp.txt” in write-mode only?
outfile = open(“c:\temp.txt”, “w”)
outfile = open(“c:\\temp.txt”, “w”)
outfile = open(file = “c:\temp.txt”, “w+”)
outfile = open(file = “c:\\temp.txt”, “w+”)
Which of the following command is used to open a file “c:\temp.txt” in append-mode?
outfile = open(“c:/temp.txt”, “a”)
outfile = open(“c:\\temp.txt”, “rw”)
outfile = open(“c:\temp.txt”, “w+”)
outfile = open(“c:\\temp.txt”, “r+”)
outfile = open(“c:\\temp.txt”, “a”)
Which of the following commands can be used to read “n” number of characters from a file using the file object <file>?
file.read(n)
n = file.read()
file.readline(n)
file.readlines()
Which of the following commands can be used to read the entire contents of a file as a string using the file object <tmpfile>?
tmpfile.read(n)
tmpfile.read()
tmpfile.readline()
tmpfile.readlines()
Which of the following commands can be used to read the next line in a file using the file object <tmpfile>?
tmpfile.read(n)
tmpfile.read()
tmpfile.readline()
tmpfile.readlines()
Which of the following commands can be used to read the remaining lines in a file using the file object <tmpfile>?
tmpfile.read(n)
tmpfile.read()
tmpfile.readline()
tmpfile.readlines()
What does the <readlines()> method returns?
str
a list of lines
list of single characters
list of integers
Which of the following command is used to open a file “c:\temp.txt” for writing in binary format only?
outfile = open(“c:\temp.txt”, “w”)
outfile = open(“c:\\temp.txt”, “wb”)
outfile = open(“c:\temp.txt”, “w+”)
outfile = open(“c:\\temp.txt”, “wb+”)
Which of the following command is used to open a file “c:\temp.txt” for reading in binary format only?
outfile = open(“c:\temp.txt”, “r”)
outfile = open(“c:\\temp.txt”, “rb”)
outfile = open(“c:\temp.txt”, “r+”)
outfile = open(“c:\\temp.txt”, “rb+”)
