问答详情
源自:2-13 python中编写带参数decorator

这两种写法有什么区别

 t1=time.time()

            r=f(*args,**kw)

            t2=time.time()

            if unit=='ms':

                t=(t2-t1)*1000

            elif unit=='s':

                t=t2-t1

            else:

                print 'none'

            print 'call %s() in %f%s'%(f.__name__,t,unit)

            return r

我一开始写成

 t1=time.time()

            r=f(*args,**kw)

            t2=time.time()

            t=t2-t1

            if unit=='ms':

                return t*1000

            elif unit=='s':

                return t

            else:

                print 'none'

            print 'call %s() in %f%s'%(f.__name__,t,unit)

            return r

为什么第二种最后一句print并没有打印呢? 仅仅打印了f的结果。先写一个t=t2-t1为什么不可以??

提问者:weixin_精慕门3117849 2018-12-26 23:42

个回答