Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. #short code snippet to understand power of decorators
  2.  
  3. def decorator_function(original_function):
  4. def wrapper_function():
  5. original_function()
  6. #...here we will add the....#
  7. #....extra code.......#
  8. #..so we never modified original function...#
  9. return 5 * 5
  10. return wrapper_function
  11.  
  12.  
  13. #define 'original function'
  14.  
  15. def display():
  16. print('hello there')
  17.  
  18. decorated_display = decorator_function(display)
  19.  
  20. twenty_five = decorated_display()
  21. print(twenty_five)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement