为了账号安全,请及时绑定邮箱和手机立即绑定

请打神指教,为什么我的运行结果打印了无数次 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)


正在回答

1 回答

  t = time.ctime() *1000 if unit =='ms' else time.time()

首先题目要求是获取计算时间

第二time.ctime()返回易读的字符串模式的当前时间

 t = time.ctime() *1000就肯定会出错,去掉*1000就不会打印了无数次 t


0 回复 有任何疑惑可以回复我~
#1

人间世支离疏

*1000就是把当前时间打印1000次,所以会出现打印无数t
2019-05-07 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
python进阶
  • 参与学习       255792    人
  • 解答问题       2946    个

学习函数式、模块和面向对象编程,掌握Python高级程序设计

进入课程

请打神指教,为什么我的运行结果打印了无数次 t ?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信