Discuss / Python / 练习2:带参数

练习2:带参数

Topic source
def log2(text):    def decorator(func):        #把原始数据的__name__复制到wrapper()函数中        @functools.wraps(func)        def wrapper(*args, **kw):            print("begin_call")            res = func(*args, **kw)            print("%s is %s." % (func.__name__, text))            print("end_call")            return res        return wrapper    return decorator@log2('execute')def f():    passf()

  • 1

Reply