小结的答案
Topic source这样的话17422
#2 Created at 2/4/2020 16:26
你这个小结2的第一个@log()包含了括号,但老师说的是@log 没有括号,还是我理解错了。。。。
考虑到你说的,我理解错了 ,故修改如下,你看看对不对
import types
def logg(*argv): #接收@时的参数和f2函数的定义
#logg无参数情况下argv获取f2()
if argv: #考虑logg()
t=argv[0]
def dec(func): #传入f2函数的定义
@functools.wraps(func)
def wrapper(*argv): #传入f2所带的参数
if not isinstance(t,types.FunctionType):
print('%s %s()' % (t,func.__name__))
else:
print('call %s()' % func.__name__)
return func(*argv)
return wrapper
if isinstance(t,types.FunctionType):
return dec(t)
else:
return dec
@logg
def f2():
print(time.strftime('%Y-%m-%d',time.localtime()))
@logg('execute')
def f3():
print(time.strftime('%y-%m-%d',time.localtime()))
g2=f2()
g3=f3()
- 1
叫红烧排骨把