pestiand82

Decoration

Sep 22nd, 2019
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import time, random
  2.  
  3. # decorator function
  4. def my_timer(func):
  5.  
  6.     def wrapper(*args, **kwargs):
  7.         print("my_timer call")
  8.  
  9.         start = time.time()
  10.         result = func(*args, **kwargs)
  11.         print("my_timer result:", time.time()-start)
  12.  
  13.         return result
  14.  
  15.     return wrapper
  16.  
  17.  
  18. def print_something_decorator(func):
  19.  
  20.     def wrapper(*args, **kwargs):
  21.         print("print_something_decorator call")
  22.         return func(*args, **kwargs)
  23.  
  24.     return wrapper
  25.  
  26. @my_timer
  27. @print_something_decorator
  28. def get_all_files(root_folder):
  29.     print("Listing all files in", root_folder)
  30.     time.sleep( random.randint(2,10) )
  31.     print("Data ready!")
  32.  
  33.  
  34. get_all_files("c:/temp/photos")
Add Comment
Please, Sign In to add comment