#!/usr/bin/env python3
from functools import wraps
import time
def decor1(param):
'''
支持@decor1、@decor1('text')调用
'''
def is_func():
func = param
@wraps(func)
def wrapper1(*args, **kw):
print('call start')
ts = time.time()
res = func(*args, **kw)
te = time.time()
print('call end')
print('run time:%s s'% (te -ts))
return res
return wrapper1
def is_str():
text = param
def text_deco(func):
@wraps(func)
def wrapper1(*args, **kw):
print(text)
print('call start')
ts = time.time()
res = func(*args, **kw)
te = time.time()
print('call end')
print('run time:%s s'%(te - ts
装饰器decorator
最新推荐文章于 2024-03-12 20:59:50 发布
本文详细探讨了Python中的装饰器,解释了它们的工作原理,并通过实例展示了如何使用装饰器来增强函数功能,包括日志记录、性能测试和权限检查等应用场景。
摘要由CSDN通过智能技术生成