Python - Decorators

stay in the pit

Refer to Fluent_Python's notes, http://www.cnblogs.com/allen2333/p/8848010.html

1.

import functools


def wrapper(func):
    @functools.wraps(func)  # 帮助我们设置函数的元信息,注释看看。保存原函数某些信息
    def inner(*args, **kwargs):
        return func(*args, **kwargs)

    return inner


@wrapper
def f1():
    pass


@wrapper
def f2():
    pass


print(f1.__name__)
print(f2.__name__)

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326624252&siteId=291194637