如何解决Ubuntu中的时间模块

时间:2019-07-20 03:15:34

标签: python-3.x

from functools import wraps
from functools import time

def func(any_fuc):
  @wraps(any_fuc)
  def func2(*args,**kwargs):
    print('this is functions run time')
    any_fuc(*args,**kwargs)
  return func2


@func
t1 = time.time()
def new_func(a,b):
  return a+b

print(new_func(1,3))

t2 = time.time()
print(t2-t1)






@func
t1 = time.time()
def new_func(a,b):
  return a+b

print(new_func(1,3))

t2 = time.time()
print(t2-t1)

错误:

  File "main.py", line 13
    t1 = time.time()
     ^
SyntaxError: invalid syntax


1 个答案:

答案 0 :(得分:0)

在赋值语句之前不允许使用修饰符。仅在函数定义,类定义和协程定义之前允许使用装饰器。您可以阅读有关装饰器herehere

的更多信息
t1 = time.time()

@func
def new_func(a,b):
  return a+b