Guest User

Untitled

a guest
May 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. # This is the decorator, or Around aspect
  2. def logging_wrapper(f):
  3. def wrapping_function(*args, **kwargs):
  4. print('Entering function: %s' % f.__name__)
  5. print('Arguments:', args)
  6. result = f(*args, **kwargs)
  7. print('Finished function: %s' % f.__name__)
  8. print('Result:', result)
  9. return result
  10.  
  11. return wrapping_function
  12.  
  13.  
  14. # This is how to use the decorator
  15. @logging_wrapper
  16. def multiply(a, b):
  17. return a * b
  18.  
  19.  
  20. @logging_wrapper
  21. def divide(a, b):
  22. return a / b
  23.  
  24.  
  25. multiply(34, 45)
  26. # Entering function: multiply
  27. # Arguments: (34, 45)
  28. # Finished function: multiply
  29. # Result: 1530
  30. divide(10, 3)
  31. # Entering function: divide
  32. # Arguments: (10, 3)
  33. # Finished function: divide
  34. # Result: 3.3333333333333335
Add Comment
Please, Sign In to add comment