PYTHON修饰器

#python 修饰器
def test(func) :
    def exe_func(*args, **kwagrs) :
        print("begin");
        res = func(*args, **kwagrs);
        print("end");
        return res;
    return exe_func;

#函数
@test
def myfunc(a, b):
    return a + b;


#实行
testres = myfunc(10, 20);
print(testres);

 

test函数可以来装饰 myfunc
的前后执行,因此aop能够简单的进行实现

posted @ 2017-01-23 13:53  spchenjie  阅读(192)  评论(0编辑  收藏  举报