Wrapping a class set method

snoe case.nelson at gmail.com
Wed Jul 27 14:42:24 EDT 2005


Hi there,

I have the following simplified classes:

class Project:
    def __init__(self,pname):
        self.devices = {} # Dictionary of Device objects
        self.pname = pname

    def setpname(self,pname):
        self.pname = pname

    def adddevice(self,dname):
        self.devices[dname] = Device(self,dname)

class Device:
    def __init__(self,parent,dname):
        self.parent = parent
        self.dname = dname

    def setdname(self,dname):
        self.dname = dname

Now, what I would like to do is wrap all of the set/add methods in a
function that pickles the Project object. I would then save the pickled
objects and use them to undo any changes to the above data structures.

I have a suspicion that there's an easier way to do this than
explicitly adding a Project.pickleme() call to the beginning of all of
my set/add methods.

So is there a way to wrap methods for this type of functionality or is
there another way of doing this, maybe without using setter methods?




More information about the Python-list mailing list