#!/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 h = Hook() h.pre_func = lambda *args, **kwargs: print 'asd' c = C() c.f(1)