python使用装饰器记录函数执行次数
时间:2021-07-09 23:18:13
收藏:0
阅读:20
‘‘‘
version: 0.2.0
Author: AbsoluteThree
Date: 2021-07-09 14:24:22
LastEditors: AbsoluteThree
LastEditTime: 2021-07-09 19:44:05
‘‘‘
1、利用装饰器,记录函数的运行次数
def func(f):
i=0
def func1():
nonlocal i
i+=1
f()
print(‘函数运行了%s次‘%i)
return func1
@func
def test():
pass
test()
test()
[Running] python -u "a:\LANGUAGE\py_text\a.py"
函数运行了1次
函数运行了2次
[Done] exited with code=0 in 0.117 seconds
原文:https://www.cnblogs.com/absolutethree/p/14992273.html
评论(0)