name "_self __class__ __name__ name self __attribute_names append(namedef save(self)with open(self filename"wb"as fhdata [for name in self __attribute_namesdata append(getattr(selfname)pickle dump(datafhpickle highest_protocoldef load(self)with open(self filename"rb"as fhdata pickle load(fhfor namevalue in zip(self __attribute_namesdata)setattr(selfnamevaluethe class has two attributesfilenamewhich is public and can be changed at any timeand __attribute_nameswhich is fixed and can be set only when the instance is created the save(method iterates over all the attribute names and creates list called data that holds the value of each attribute to be savedit then saves the data into pickle the with statement ensures that the file is closed if it was successfully openedand any file or pickle exceptions are passed up to the caller the load(method iterates over the attribute names and the corresponding data items that have been loaded and sets each attribute to its loaded value here is the start of the filestack class that multiply-inherits the undo class from the previous subsection and this subsection' loadsave classclass filestack(undoloadsave)def __init__(selffilename)undo __init__(selfloadsave __init__(selffilename"__stack"self __stack [def load(self)super(load(self clear(the rest of the class is just the same as the stack classso we have not reproduced it here instead of using super(in the __init__(method we must specify the base classes that we initialize since super(cannot guess our intentions for the loadsave initialization we pass the filename to use and also the names of the attributes we want savedin this case just onethe private __stack (we don' want to save the __undosand nor could we in this case since it is list of methods and is therefore unpicklable