Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #short code snippet to understand power of decorators
- def decorator_function(original_function):
- def wrapper_function():
- original_function()
- #...here we will add the....#
- #....extra code.......#
- #..so we never modified original function...#
- return 5 * 5
- return wrapper_function
- #define 'original function'
- def display():
- print('hello there')
- decorated_display = decorator_function(display)
- twenty_five = decorated_display()
- print(twenty_five)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement