PYTHON中装饰器不能使用
我在PYTHON命令行中复制输入
import time
def performance(f):
def fn(*args, **kw):
t1 = time.time()
r = f(*args, **kw)
t2 = time.time()
print 'call %s() in %fs' % (f.__name__, (t2 - t1))
return r
return fn
@performance
def factorial(n):
return reduce(lambda x,y: x*y, range(1, n+1))
print factorial
编译器不能给出答案,报错:
File "<stdin>", line 4
print factorial(10)
^
SyntaxError: invalid syntax
请问这是为什么