import time
def time(func):
print(time.ctime())
return func()
@time # 从这里可以看出@time 等价于 time(xxx()),但是这种写法你得考虑python代码的执行顺序
def xxx():
print('Hello world!')
函数首行不需要缩进
版权声明:本文为jpmsdn原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。
import time
def time(func):
print(time.ctime())
return func()
@time # 从这里可以看出@time 等价于 time(xxx()),但是这种写法你得考虑python代码的执行顺序
def xxx():
print('Hello world!')
函数首行不需要缩进