1. a file name and file properties
2. a file name and mode
3. a file name and size
4. a file name and data type
Title
When reading a file in Python, what information must be provided?
type
mc
Section
7.1 Reading and Writing Text Files
id
testbank-py-1-ch07-01
2. Before accessing a file, the program must:
1. name the file
2. read the file
3. open the file
4. close the file
Title
Before accessing a file, what must be done to allow access to the file?
type
mc
Section
7.1 Reading and Writing Text Files
id
testbank-py-1-ch07-02
3. After executing the following code snippet, what part is the file object?
infile = open("input.txt", "r")
1. infile
2. "input.txt"
3. "r"
4. input
Title
After executing the following code snippet, what part is the file object?
type
mc
Section
7.1 Reading and Writing Text Files
id
testbank-py-1-ch07-03
4. In the following code snippet, what does the "r" represent?
,infile = open("input.txt", "r")
1. replace
2. recursive
3. random
4. read
Title
In the following code snippet, what does the "r" represent?
type
mc
Section
7.1 Reading and Writing Text Files
id
testbank-py-1-ch07-04
5. In the following code snippet, what does the "w" represent?
outfile = open("output.txt", "w")
1. wrapper
2. write
3. width
4. web
Title
In the following code snippet, what does the "w" represent?
type
mc
Section
7.1 Reading and Writing Text Files
id
testbank-py-1-ch07-05
6. In the following code snippet, what happens if the "output.txt" file does not
exist?
outfile = open("output.txt", "w")
1. An error message is displayed
2. An empty file is created
3. Nothing, this statement is ignored
4. A new file is created with at least one record
Title
In the following code snippet, what happens if the "output.txt" file does not exist?
type
mc
Section
7.1 Reading and Writing Text Files
, id
testbank-py-1-ch07-06
7. In the following code snippet, what happens if the "output.txt" file already
exists?
outfile = open("output.txt", "w")
1. Any new data is appended to the end
2. The existing file is emptied
3. Nothing, this statement is ignored
4. An error message is displayed
Title
In the following code snippet, what happens if the "output.txt" file already exists?
type
mc
Section
7.1 Reading and Writing Text Files
id
testbank-py-1-ch07-07
8. What method ensures that the output has been written to the disk file?
1. commit()
2. write()
3. close()
4. complete()
Title
What method ensures that the output has been written to the disk file?
type
mc
Section
7.1 Reading and Writing Text Files
id
testbank-py-1-ch07-08
9. Once a file has been opened, what method is used to read data from a file?
1. readline()
2. readfile()
, 3. readln()
4. open()
Title
Once a file has been opened, what method is used to read data from a file?
type
mc
Section
7.1 Reading and Writing Text Files
id
testbank-py-2-ch07-09
from
testbank-py-1-ch07-09
10. The readline method reads text until an end of line symbol is encountered, how is
an end of line character represented?
1. \r
2. \t
3. ""
4. \n
Title
The readline method reads text until an end of line symbol is encountered, how is an
end of line character represented?
type
mc
Section
7.1 Reading and Writing Text Files
id
testbank-py-1-ch07-10
11. What is returned when the readline method reaches the end of the file?
1. \r
2. \t