Python Files
Sign in to Google to save your progress. Learn more
Email *
Programme
Given the architecture and terminology we introduced in Chapter 1, where are files stored?
1 point
Clear selection
What is stored in a "file handle" that is returned from a successful open() call?
1 point
Clear selection
What do we use the second parameter of the open() call to indicate?
1 point
Clear selection
What Python function would you use if you wanted to prompt the user for a file name to open?
1 point
Clear selection
What is the purpose of the newline character in text files?
1 point
Clear selection
If we open a file as follows:
xfile = open('mbox.txt')

What statement would we use to read the file one line at a time?
1 point
Clear selection
What is the purpose of the following Python code?
fhand = open('mbox.txt')
x = 0
for line in fhand:
       x = x + 1
print(x)
1 point
Clear selection
If you write a Python program to read a text file and you see extra blank lines in the output that are not present in the file input as shown below, what Python string function will likely solve the problem?
From: stephen.marquard@uct.ac.za

From: louis@media.berkeley.edu

From: zqian@umich.edu

From: rjlowe@iupui.edu

...
1 point
Clear selection
The following code sequence fails with a traceback when the user enters a file that does not exist. How would you avoid the traceback and make it so you could print out your own error message when a bad file name was entered?
fname = input('Enter the file name: ')
fhand = open(fname)
1 point
Clear selection
What does the following Python code do?
fhand = open('mbox-short.txt')
inp = fhand.read()
1 point
Clear selection
Submit
Clear form
This form was created inside of Kalinga Institute of Social Sciences. Report Abuse