object-oriented programming we had to open the file in binary mode when reading pickles no protocol is specified--the pickle load(function is smart enough to work out the protocol for itself def load(selffilename=none)if filename is not noneself filename filename if not self filenameraise nofilenameerror(fh none tryfh open(self filename"rb"data pickle load(fh(self __widthself __heightself __backgroundself __datadata self __colors (set(self __data values(){self __background}except (environmenterrorpickle unpicklingerroras errraise loaderror(str(err)finallyif fh is not nonefh close(this function starts off the same as the save(function to get the filename of the file to load the file must be opened in read binary modeand the data is read using the single statementdata pickle load(fhthe data object is an exact reconstruction of the one we savedso in this case it is list with the width and height integersthe background color stringand the dictionary of coordinate-color items we use tuple unpacking to assign each of the data list' items to the appropriate variableso any previously held image data is (correctlylost the set of unique colors is reconstructed by making set of all the colors in the coordinate-color dictionary and then adding the background color def export(selffilename)if filename lower(endswith(xpm")self __export_xpm(filenameelseraise exporterror("unsupported export formatos path splitext(filename)[ ]we have provided one generic export method that uses the file extension to determine which private method to call--or raises an exception for file formats that cannot be exported in this case we only support saving to xpm files (and then only for images with fewer than colorswe haven' quoted the