Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This is the decorator, or Around aspect
- def logging_wrapper(f):
- def wrapping_function(*args, **kwargs):
- print('Entering function: %s' % f.__name__)
- print('Arguments:', args)
- result = f(*args, **kwargs)
- print('Finished function: %s' % f.__name__)
- print('Result:', result)
- return result
- return wrapping_function
- # This is how to use the decorator
- @logging_wrapper
- def multiply(a, b):
- return a * b
- @logging_wrapper
- def divide(a, b):
- return a / b
- multiply(34, 45)
- # Entering function: multiply
- # Arguments: (34, 45)
- # Finished function: multiply
- # Result: 1530
- divide(10, 3)
- # Entering function: divide
- # Arguments: (10, 3)
- # Finished function: divide
- # Result: 3.3333333333333335
Add Comment
Please, Sign In to add comment