Page 259 -
P. 259
web development
Here is the outline for a new module called athletemodel.py, which provides the
functionality described on the previous page. Some of the code is already provided for you. Your
job is to provide the rest of the code to the put_to_store() and get_from_store()
functions. Don’t forget to protect any file I/O calls.
import pickle
from athletelist import AthleteList
def get_coach_data(filename):
# Not shown here as it has not changed since the last chapter.
def put_to_store(files_list): This function is called with a
all_athletes = {} list of filenames as its sole
You need code in argument.
here to populate
the dictionary with
the data from the
files.
And don’t forget
to save the
dictionary to a
pickle (and check
for file I/O errors).
return(all_athletes)
def get_from_store():
Both functions
all_athletes = {}
need to return
Get the dictionary a dictionary of
AthleteLists.
from the file, so
that it can be
returned to the
caller.
return(all_athletes)
you are here 4 223