码迷,mamicode.com
首页 > 其他好文 > 详细

装饰器

时间:2020-03-27 15:37:54      阅读:68      评论:0      收藏:0      [点我收藏+]

标签:remove   技术   exe   alt   style   int   bsp   color   on()   

# -*- 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)

输出结果

技术图片

 

装饰器

标签:remove   技术   exe   alt   style   int   bsp   color   on()   

原文地址:https://www.cnblogs.com/python-kp/p/12581769.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!