#!/usr/local/bin/python2 class Hook(object): def pre_func(*args, **kwargs): pass def post_func(*args, **kwargs): pass def attach(self, method, instance): def f(*args, **kwargs): self.pre_func(*args, **kwargs) method(*args, **kwargs) self.post_func(*args, **kwargs) setattr(instance, method.__name__, f) class C: def f(self, *args, **kwargs): print args, kwargs def f(*args, **kwargs): print 'asd' h = Hook() h.pre_func = f c = C() h.attach(c.f, c) c.f(1)