-
What are the two things that uniquely specify a file?
name and location
-
Write the Python statement that would create a file object for the file
scores.txt for reading and assign it to the variable
scores_file.
scores_file = open("scores.txt", "r")
-
Write the Python statement that would create a file object for the file
scores.txt for writing and assign it to the variable
scores_file.
scores_file = open("scores.txt", "w")
-
Write the Python statement that would create a file object for the file
scores.txt for appending and assign it to the variable
scores_file.
scores_file = open("scores.txt", "a")
-
What happens when you use the append access mode on a file?
adds text to the bottom of the file
-
If you wanted to read a SINGLE LINE of a file for which you had the file
variable scores_file and store it in the
variable line what Python statement
would you write?
line = scores_file.readline()
-
What is the empty string?
a string with no characters in it
-
What does readline() return when it gets to the
end of the file?
the empty string
-
What must you do if you want to write an integer to a text file?
convert it into a string
-
What must you do if you read "87" from a text file and want to add it to another number?
conver it to an integer
-
Write a
for
loop that reads and prints a file. Assume you have already
created a file object and have stored a reference to it in the variable file.
for line in file:
print(line.rstrip())