# Reviews
What type of file access jumps directly to any piece of data in a file without reading the data that came before it?
Assume that the customer file references a file object, and the file was opened using the
w
mode specifier. How would you write the stringMary Smith
to the file?What statement can be used to handle some of the run-time errors in a program?
What statement below is a correct call to function func?
def func(farg, **kwargs):
print ("formal arg:", farg)
for key in kwargs:
print ("another keyword arg: %s: %s" %
(key, kwargs[key]))
Which of these is associated with a specific file and provides a way for the program to work with that file?
Which method will return an empty string when it has attempted to read beyond the end of a file?
What will be displayed given the following function definition and function call?
def divide(x, y):
try:
result = x / y
except ZeroDivisionError:
print ("division by zero!")
else:
print ("result is", result)
finally:
print ("executing finally clause")
divide(2, 1)
result is 2.0
executing finally clause
Questions 8-9 refer to the following code.
# Open a file
fo = open("foo.txt", "w")
fo.write( "Python is a great language.\nYeah its great!!\n");
# Close opened file
fo.close()
What will be displayed given the code?
# Open a file
fo = open("foo.txt", "r+")
str = fo.read();
print ("Read String is : ", str)
# Close opened file
fo.close()
Read String is : Python is a great language.
Yeah its great!!What will be displayed given the code?
# Open a file
fo = open("foo.txt", "r+")
str = fo.readline();
print ("Read String is : ", str)
# Close opened file
fo.close()
Read String is : Python is a great language.