交作业
Topic sourcefrom collections import Iterable
import functools
def log(*agrs):
if isinstance(agrs[0],Iterable):
def decorator(func):
@functools.wraps(func)
def wrapper(*agrs1,**kw):
for x in agrs:
print('%s' % x)
return func(*agrs1,**kw)
return wrapper
return decorator
else:
@functools.wraps(agrs[0])
def wrapper(*agrs1,**kw):
print('@log')
return agrs[0](*agrs1,**kw)
return wrapper
- 1
笨笨的大桉树
from collections import Iterable import functools
def log(agrs): if isinstance(agrs[0],Iterable): def decorator(func): @functools.wraps(func) def wrapper(agrs1,kw): for x in agrs: print('%s' % x) return func(*agrs1,kw) return wrapper return decorator else: @functools.wraps(agrs[0]) def wrapper(agrs1,**kw): print('@log') return agrs[0](agrs1,**kw) return wrapper