python函数装饰器的应用过程
python函数装饰器的应用过程
1、应用过程
一般是定义在一个独立模块中,使用时会被导入到其它模块;
函数装饰器会在内部定义一个新函数,然后返回。
2、实例
定义被装饰函数的代码处,就会执行该装饰器。
registry=[]
defregister(func):
logging.info('[register]func->%s',func)
registry.append(func)
returnfunc
@register
deff1():
logging.info('f1->%s',f1)
@register
deff2():
logging.info('f2->%s',f2)
deff3():
logging.info('f3->%s',f3)
defmain():
logging.info('main->%s',main)
logging.info('registry->%s',registry)
f1()
f2()
f3()
if__name__=='__main__':
main()
以上就是python函数装饰器的应用过程,希望能对大家有所帮助。更多Python学习教程请关注IT培训机构:千锋教育。

相关推荐HOT
更多>>
python函数装饰器的应用过程
python函数装饰器的应用过程1、应用过程一般是定义在一个独立模块中,使用时会被导入到其它模块;函数装饰器会在内部定义一个新函数,然后返回。...详情>>
2023-11-10 22:33:56
python实现异步的两种框架
python实现异步的两种框架Python实现异步的框架有很多,但是核心思想大概是基于下面两种方式twistergeventtwister1、twistertwister思想是将异...详情>>
2023-11-10 22:11:26
python函数形式如何实现生成器
python函数形式如何实现生成器1、说明生成器也是迭代器,但只能迭代一次。这是因为它们没有存储所有的值,而是在运行过程中产生值。你一直在使...详情>>
2023-11-10 21:50:58
python描述符的两种类型
python描述符的两种类型1、分类数据描述符:实现了__get__和__set__两种方法的描述符非数据描述符:只实现了__get__一种方法的描述符2、实例#数...详情>>
2023-11-10 21:30:01