Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. def a_new_decorator(a_func):
  2. def wrapTheFunction():
  3. print("I am doing some boring work before executing a_func()")
  4.  
  5. a_func()
  6.  
  7. print("I am doing some boring work after executing a_func()")
  8.  
  9. return wrapTheFunction
  10.  
  11.  
  12. def a_function_requiring_decoration():
  13. print("I am the function which needs some decoration to remove my foul smell")
  14.  
  15.  
  16. a_function_requiring_decoration()
  17. # outputs: "I am the function which needs some decoration to remove my foul smell"
  18.  
  19. a_function_requiring_decoration = a_new_decorator(a_function_requiring_decoration)
  20. # now a_function_requiring_decoration is wrapped by wrapTheFunction()
  21.  
  22. a_function_requiring_decoration()
  23. # outputs:I am doing some boring work before executing a_func()
  24. # I am the function which needs some decoration to remove my foul smell
  25. # I am doing some boring work after executing a_func()
  26. print a_function_requiring_decoration.__name__
  27. # outputs:wrapTheFunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement