Discuss / Python / 用可变参数,想传多少参数就传多少

用可变参数,想传多少参数就传多少

Topic source

浪过扬帆

#1 Created at ... [Delete] [Delete and Lock User]
def log(*text):
    def dec(fn):
        @functools.wraps(fn)
        def wrapper(*args, **kw):
            print('函数名:' + fn.__name__)
            if len(text) != 0:
                print('传入了参数:', end='')
                print(text)
            else:
                print('未传入参数')
            ret = fn(*args, **kw)
            return ret
        return wrapper
    return dec

  • 1

Reply