
Python File handling - 2
Authored by Bessie Carl
Computers
12th Grade
Used 79+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
20 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
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+”)
2.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
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+”)
3.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
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”, “w+”)
outfile = open(“c:\\temp.txt”, “a”)
outfile = open(“c:\\temp.txt”, “r+”)
4.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
Which of the following statements are true regarding the opening modes of a file?
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, an error occurs.
C. When you open a file for reading, if the file does not exist, the program will open an empty file.
D. When you open a file for writing, if the file does not exist, a new file is created.
E. When you open a file for writing, if the file exists, the existing file is overwritten with the new file.
Only A
A and B
A, D and E
A, B and E
5.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
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()
6.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
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()
7.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
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()
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?