新手求教各位大佬:
1.为什么还要在 timeslong 函数里再定义一个 call 函数?import time
def timeslong(func):
def call():
start = time.clock()
print("It's time starting ! ")
func()
print("It's time ending ! ")
end = time.clock()
return "It's used : %s ." % (end - start)
return call
@timeslong
def f():
y = 0
for i in range(10):
y = y + i + 1
print(y)
return y
print(f())
2.如果代码修改如下,为什么不执行“return "It's used : %s ." % (end - start)”?import time
def timeslong(func):
start = time.perf_counter()
print("It's time starting ! ")
func()
print("It's time ending ! ")
end = time.perf_counter()
return "It's used : %s ." % (end - start)
def f():
y = 0
for i in range(10):
y = y + i + 1
print(y)
return y
timeslong(f)
|