装饰器
Posted python-kp
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了装饰器相关的知识,希望对你有一定的参考价值。
# -*- coding:utf-8 def a_new_decorator(a_func): def wrapTheFunction(): print("I am doing some boring work before executing a_func()") a_func() print("I am doing some boring work after executing a_func()") return wrapTheFunction @a_new_decorator def a_function_requiring_decoration(): """Hey you! Decorate me!""" print("I am the function which needs some decoration to " "remove my foul smell") a_function_requiring_decoration() a_function_requiring_decoration = a_new_decorator(a_function_requiring_decoration)
输出结果:
以上是关于装饰器的主要内容,如果未能解决你的问题,请参考以下文章