用python实现函数调用拦截,python函数拦截,写的这个关于用pytho


写的这个关于用python实现函数调用拦截,原因是因为,都知道动态语言提供了在运行时改变程序结构的能力。但是有些人认为这会造成混乱,可是我的观点并不是这样。我认为这些功能有时候会提供巨大的方便。

所以这里举个例子:函数调用拦截是aop的基础,用python实现这个功能非常简单,看下边的python代码:

#Targetclass Target:    def targetFunc(self):        print "targetFunction"#www.iplaypy.com#aoptemp=Target.targetFuncdef foo(self):    print "before call"    temp(self)    print "after call"Target.targetFunc=foo#see resultt=Target()t.targetFunc() 

编橙之家文章,

评论关闭