請打神指教,為什么我的運行結果打印了無數次 t ?
import time
def performance(unit):
??? def performance1(f):
??????? def performance2(*args, **kw):
??????????? t = time.ctime() *1000 if unit =='ms' else time.time()
??????????? print 'call '+f.__name__+'() in',t,unit
??????????? return f (*args, **kw)
??????? return performance2
??? return performance1
@performance('ms')
def factorial(n):
??? return reduce(lambda x,y: x*y, range(1, n+1))
print factorial(10)
2019-05-07
? t = time.ctime() *1000 if unit =='ms' else time.time()
首先題目要求是獲取計算時間
第二time.ctime()返回易讀的字符串模式的當前時間
?t = time.ctime() *1000就肯定會出錯,去掉*1000就不會打印了無數次 t