def debugit(func): def func2(*x): print " in f(x,y,...); args={}".format(x) return func(*x) return func2 @debugit def f(x, y): return x + y def f1(x): # without memoization return x+1 f2_cache = {} def f2(x): # with memoization if x in f2_cache: return f2_cache[x] else: answer = x+1 f2_cache[x] = answer return answer def main(): a = f(3, 4) print "f(3,4)= {}".format(a) main()