SHARE
TWEET

Untitled

a guest Mar 19th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! usr/bin/python3.6
  2. # coding: utf-8
  3. import time
  4. from functools import wraps
  5.  
  6.  
  7. def my_logger(func):
  8.     import logging
  9.     logging.basicConfig(filename='{}.log'.format(str(func.__name__)), level=logging.DEBUG)
  10.  
  11.     @wraps(func)
  12.     def wrapper(*args, **kwargs):
  13.         logging.debug('Ran {} with args {} and kwargs {}.'.format((str(func.__name__)), args, kwargs))
  14.         return func(*args, **kwargs)
  15.  
  16.     return wrapper
  17.  
  18.  
  19. def my_timer(func):
  20.     @wraps(func)
  21.     def wrapper(*args, **kwargs):
  22.         t1 = time.time()
  23.         result = func(*args, **kwargs)
  24.         t2 = time.time() - t1
  25.         print('{} ran in {} seconds.'.format(str(func.__name__), str(t2)))
  26.         return result
  27.  
  28.     return wrapper
  29.  
  30.  
  31. @my_logger
  32. def display_func(name, age, number):
  33.     time.sleep(0.15)
  34.     print('Executing the display function...')
  35.  
  36.  
  37. @my_timer
  38. def display_timer():
  39.     time.sleep(0.558)
  40.     print('Executing display timer function...')
  41.  
  42.  
  43. if __name__ == '__main__':
  44.     display_func('James', 55, '555-1212')
  45.     display_timer()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top