def wrapmethod(func, premethod=None, postmethod=None): def w(function, *args, **kwds): if premethod: premethod(*args, **kwds) function(*args, **kwds) if postmethod: postmethod(*args, **kwds) return lambda *x,**k: w(func,*x,**k)