zoukankan      html  css  js  c++  java
  • 复习装饰器

     1 def a_new_decorator(a_func):
     2  
     3     def wrapTheFunction():
     4         print("I am doing some boring work before executing a_func()")
     5  
     6         a_func()
     7  
     8         print("I am doing some boring work after executing a_func()")
     9  
    10     return wrapTheFunction
    11  
    12 def a_function_requiring_decoration():
    13     print("I am the function which needs some decoration to remove my foul smell")
    14  
    15 a_function_requiring_decoration()
    16 #outputs: "I am the function which needs some decoration to remove my foul smell"
    17  
    18 a_function_requiring_decoration = a_new_decorator(a_function_requiring_decoration)
    19 #now a_function_requiring_decoration is wrapped by wrapTheFunction()
    20  
    21 a_function_requiring_decoration()
    22 #outputs:I am doing some boring work before executing a_func()
    23 #        I am the function which needs some decoration to remove my foul smell
    24 #        I am doing some boring work after executing a_func()
     1 @a_new_decorator
     2 def a_function_requiring_decoration():
     3     """Hey you! Decorate me!"""
     4     print("I am the function which needs some decoration to "
     5           "remove my foul smell")
     6  
     7 a_function_requiring_decoration()
     8 #outputs: I am doing some boring work before executing a_func()
     9 #         I am the function which needs some decoration to remove my foul smell
    10 #         I am doing some boring work after executing a_func()
    11  
    12 #the @a_new_decorator is just a short way of saying:
    13 a_function_requiring_decoration = a_new_decorator(a_function_requiring_decoration)
  • 相关阅读:
    InfoPath 发布表单到SharePoint库报错
    在log4net中控制nhibernate输出
    微信扫一扫(wx.scanQRCode)功能新手可能遇到的问题
    3.Zookeeper的安装和配置(集群模式)
    1.配置HDFS HA (高可用)
    2.Zookeeper工作原理(详细)
    1.Zookeeper 定义与工作原理
    js 获取元素的几种方法
    弹出层居中
    XUACompatible
  • 原文地址:https://www.cnblogs.com/ch2020/p/13260271.html
Copyright © 2011-2022 走看看