Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. from random import random, randint, choice
  2.  
  3. def our_decorator(func):
  4. def function_wrapper(*args, **kwargs):
  5. print("Before calling " + func.__name__)
  6. res = func(*args, **kwargs)
  7. print(res)
  8. print("After calling " + func.__name__)
  9. return function_wrapper
  10.  
  11. for f in [random, randint, choice]:
  12. f = our_decorator(f)
  13.  
  14. random()
  15. randint(3, 8)
  16. choice([4, 5, 6])
  17.  
  18. Before calling random
  19. <random_value>
  20. After calling random
  21. Before calling randint
  22. <random_integer>
  23. After calling randint
  24. Before calling choice
  25. <random_choice>
  26. After calling choice
  27.  
  28. <random_choice among 4,5 6>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement