pythonwrapper是什么

2023-12-14 7:49:20网络知识悟空

pythonwrapper是什么

1、说明

wrapper是装饰器的意思,装饰器本质上是一个Python函数。可以让其他函数,在不需要做任何代码变动的前提下增加额外功能,装饰器的返回值也是一个函数对象。

2、应用场景

插入日志、性能测试、事务处理、缓存、权限校验等

3、实例

无参数的装饰器。

defdebug(func):

defwrapper():

print('[DEBUG]:enter{}()'.format(func.__name__))

returnfunc()

returnwrapper

@debug

defsay_hello():

print('hello!')

say_hello()

"""

[DEBUG]:entersay_hello()

hello!

"""

以上就是pythonwrapper的介绍,大家在python中还是比较容易遇到装饰器的使用,可以在看完内容后做一些练习。更多Python学习教程请关注IT培训机构:筋斗云。

发表评论: