we can also load this data back into mailinglist object successfullym mailinglist('addresses db' email_map defaultdict({} load( email_map defaultdict({'friend @example com'{'friends\ '}'family @example com'{'family\ '}'friend @example com'{'friends\ '}}as you can seei forgot to do the load commandand it might be easy to forget the save command as well to make this little easier for anyone who wants to use our mailinglist api in their own codelet' provide the methods to support context managerdef __enter__(self)self load(return self def __exit__(selftypevaluetb)self save(these simple methods just delegate their work to load and savebut we can now write code like this in the interactive interpreter and know that all the previously stored addresses were loaded on our behalfand that the whole list will be saved to the file when we are donewith mailinglist('addresses db'as mlml add_to_group('friend @example com''friends'ml send_mailing("what' up""hey friendshow' it going"'meexample com''friends'exercises if you haven' encountered the with statements and context managers beforei encourage youas usualto go through your old code and find all the places you were opening filesand make sure they are safely closed using the with statement look for places that you could write your own context managers as well ugly or repetitive try finally clauses are good place to startbut you may find them useful any time you need to do before and/or after tasks in context