Python装饰器 name binding

python 装饰器 函数或方法

@decorate

def fun(a,b):

...

fun(1,2) 时即

fun=decorate(fun)

fun(1,2)

 

若decorate有参数则相当于

fun=decorate(参数)(fun)

 

若装饰类

则一样的,更新方法、属性。 同样的是name binding

 

   @functools.wraps(func)

若在装饰器有这样的字段会把原函数的元信息也赋值到装饰器内部

 

参考:http://www.cnblogs.com/wupeiqi/articles/4980620.html

http://www.cnblogs.com/vamei/archive/2013/02/16/2820212.html

posted on 2018-05-27 16:14  BioinformaticsMaster  阅读(245)  评论(0编辑  收藏  举报

导航