def html_tags(tag_name):
    def wrapper_(func):
        def wrapper(*args, **kwargs):
            content = func(*args, **kwargs)
            return "<{tag}>{content}</{tag}>".format(tag=tag_name, content=content)
        return wrapper
    return wrapper_

#html_tags('b')(hello)(name='Andy')
#装饰器的拆开执行原理

#@html_tags('b')
def hello(name='Toby'):
    return 'Hello {}!'.format(name)

#print(hello())
# 不用@的写法如下
print(html_tags('b')(hello)())
# html_tag('b') 是一个闭包,它接受一个函数(hello),并返回一个函数

# hello = html_tags('b')(hello)
# hello = wrapper_(hello)
# hello = wrapper
#hello()
#wrapper(name='Toby')

相关文章: