|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import time
def time_master(func):
print("开始运行程序")
start=time.time()
func()
stop=time.time()
print("结束程序运行")
print(f"一共耗费{(stop-start):2f}秒。")
return call_func
@time_master
def Myfunc():
time.sleep(2)
print("hello")
Myfunc()
运行结果:
==
开始运行程序
hello
结束程序运行
一共耗费2.020955秒。
Traceback (most recent call last):
File "C:/python学习/time_master.py", line 11, in <module>
@time_master
File "C:/python学习/time_master.py", line 9, in time_master
return call_func
NameError: name 'call_func' is not defined
|
|