python 修饰符的理解和一个通用模版例子

例子是多个修饰符参数的例子


def decorator_factory(enter_message, exit_message):
    # We're going to return this decorator
    def simple_decorator(f):
        def wrapper(*args, **kwds):
            print enter_message
            f(*args, **kwds)
            print exit_message
        return wrapper
    return simple_decorator


@decorator_factory("Start", "End")
def hello(username,name):
    print "Hello World"
    print username,name


hello('ddddddddddddddd','ffff')
运行结果
Start
Hello World
ddddddddddddddd ffff
End

你可能感兴趣的:(python)