Deck 7: files and Exceptions
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/35
Play
Full screen (f)
Deck 7: files and Exceptions
1
Assume that the customer file references a file object, and the file was opened using the 'w' mode specifier. How would you write the string 'Mary Smith' to the file?
A) customer_file.write('Mary Smith')
B) customer.write('w','Mary Smith')
C) customer.input('Mary Smith')
D) customer.write('Mary Smith')
A) customer_file.write('Mary Smith')
B) customer.write('w','Mary Smith')
C) customer.input('Mary Smith')
D) customer.write('Mary Smith')
D
2
What statement can be used to handle some of the run-time errors in a program?
A) exception statement
B) try statement
C) try/except statement
D) exception handler statement
A) exception statement
B) try statement
C) try/except statement
D) exception handler statement
C
t/false
t/false
3
What do you call the process of retrieving data from a file?
A) Retrieving data
B) Reading data
C) Input data
D) Get data
A) Retrieving data
B) Reading data
C) Input data
D) Get data
B
4
How many types of files are there?
A) One
B) Two
C) Three
D) four
A) One
B) Two
C) Three
D) four
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
5
When a piece of data is read from a file, it is copied from the file into the program.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
6
Python allows the programmer to work with text and number files.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
7
Which step creates a connection between a file and a program?
A) Open the file.
B) Read the file.
C) Process the file.
D) Close the file.
A) Open the file.
B) Read the file.
C) Process the file.
D) Close the file.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
8
Which method could be used to strip specific characters from the end of a string?
A) estrip
B) rstrip
C) strip
D) remove
A) estrip
B) rstrip
C) strip
D) remove
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
9
Which of these is associated with a specific file and provides a way for the program to work with that file?
A) filename
B) Extension
C) file object
D) file variable
A) filename
B) Extension
C) file object
D) file variable
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
10
If a file with the specified name already exists when the file is opened, and the file is opened in 'w' mode, then an alert will appear on the screen.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
11
Which mode specifier will open a file but will not let you change the file or write to it?
A) 'w'
B) 'r'
C) 'a'
D) 'e'
A) 'w'
B) 'r'
C) 'a'
D) 'e'
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
12
A(n) _____ access file is also known as a direct access file.
A) sequential
B) random
C) numbered
D) text
A) sequential
B) random
C) numbered
D) text
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
13
Closing a file disconnects the communication between the file and the program.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
14
In Python, there is nothing that can be done if the program tries to access a file to read that does not exist.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
15
Which mode specifier will erase the contents of a file if it already exists and create it if it does not exist?
A) 'w'
B) 'r'
C) 'a'
D) 'e'
A) 'w'
B) 'r'
C) 'a'
D) 'e'
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
16
What type of file access jumps directly to any piece of data in a file without reading the data that came before it?
A) Sequential
B) Random
C) Number
D) Text
A) Sequential
B) Random
C) Number
D) Text
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
17
Which method could be used to convert a numeric value to a string?
A) str
B) value
C) num
D) chr
A) str
B) value
C) num
D) chr
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
18
What happens when a piece of data is written to a file?
A) Data is copied from a variable in RAM to a file.
B) Data is copied from a variable in the program to a file.
C) Data is copied from the program to a file.
D) Data is copied from a file object to a file.
A) Data is copied from a variable in RAM to a file.
B) Data is copied from a variable in the program to a file.
C) Data is copied from the program to a file.
D) Data is copied from a file object to a file.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
19
Which method will return an empty string when it has attempted to read beyond the end of a file?
A) read
B) getline
C) input
D) readline
A) read
B) getline
C) input
D) readline
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
20
When a file has been opened using the 'r' mode specifier, which method will return the file's contents as a string?
A) write
B) input
C) get
D) read
A) write
B) input
C) get
D) read
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
21
The ZeroDivisionError exception is raised when the program attempts to perform a division by zero.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
22
Strings can be written directly to a file with the write method, but numbers must be converted to strings before they can be written.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
23
A(n) _______________ file contains data that has not been converted to text.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
24
It is possible to create a while loop that determines when the end of a file has been reache
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
25
A(n) _______________ access file retrieves data from the beginning of the file to the end of the file.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
26
The term _______________ file is used to describe a file from which the program gets data.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
27
When a program needs to save data for later use, it writes the data in a(n) _______________.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
28
A(n) _______________ gives information regarding the line number(s) that caused an exception.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
29
If the last line in a file is not terminated with a \n, the readline method will return the line without a \n.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
30
Programmers usually refer to the process of _______________ data in a file as "writing data to" the file.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
31
A(n) _______________ includes one or more statements that can potentially raise an exception.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
32
A(n) _______________ file contains data that has been encoded as text, using a scheme such as ASCII.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
33
An exception handler is a piece of code that is written using the try/except statement.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
34
The term _______________ file is used to describe a file to which data is written.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
35
A filename _______________ is a short sequence of characters that appear at the end of a filename preceded by a period.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck