SHARE
TWEET

Untitled

a guest Jun 16th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '''
  2. the code for the employee class is # -*- coding: utf-8 -*-
  3. """
  4. Spyder Editor
  5.  
  6. This is a temporary script file.
  7. """
  8.  
  9. import logging
  10.  
  11. logger = logging.getLogger(__name__)
  12. logger.setLevel(logging.INFO)
  13.  
  14. formatter = logging.Formatter('%(levelname)s:%(name)s:%(message)s')
  15.  
  16. file_handler = logging.FileHandler('employee.log')
  17. file_handler.setFormatter(formatter)
  18.  
  19. logger.addHandler(file_handler)
  20.  
  21.  
  22. class Employee:
  23.     """A sample Employee class"""
  24.  
  25.     def __init__(self, first, last):
  26.         self.first = first
  27.         self.last = last
  28.  
  29.         logger.info('Created Employee: {} - {}'.format(self.fullname, self.email))
  30.  
  31.     @property
  32.     def email(self):
  33.         return '{}.{}@email.com'.format(self.first, self.last)
  34.  
  35.     @property
  36.     def fullname(self):
  37.         return '{} {}'.format(self.first, self.last)
  38.  
  39.  
  40. emp_1 = Employee('John', 'Smith')
  41. emp_2 = Employee('Corey', 'Schafer')
  42. emp_3 = Employee('Jane', 'Doe')
  43.  
  44. and the code for the main program is:
  45.  
  46. import logging
  47.  
  48. import employee
  49.  
  50.  
  51. logger = logging.getLogger(__name__)
  52. logger.setLevel(logging.INFO)
  53.  
  54. formatter = logging.Formatter('%(asctime)s:%(name)s:%(message)s')
  55.  
  56. file_handler = logging.FileHandler('sample.log')
  57. file_handler.setLevel(logging.DEBUG)
  58. file_handler.setFormatter(formatter)
  59.  
  60. stream_handler = logging.StreamHandler()
  61. stream_handler.setFormatter(formatter)
  62.  
  63. logger.addHandler(file_handler)
  64. logger.addHandler(stream_handler)
  65.  
  66.  
  67.  
  68.  
  69.  
  70. def add(x, y):
  71.     """Add Function"""
  72.     return x + y
  73.  
  74.  
  75. def subtract(x, y):
  76.     """Subtract Function"""
  77.     return x - y
  78.  
  79.  
  80. def multiply(x, y):
  81.     """Multiply Function"""
  82.     return x * y
  83.  
  84.  
  85. #def divide(x, y):
  86. #    """Divide Function"""
  87. #    try:
  88. #        result = x / y
  89. #    except ZeroDivisionError:
  90. #        logger.exception('Tried to divide by zero')
  91. #    else:
  92. #        return result
  93.  
  94.  
  95. num_1 = 10
  96. num_2 = 0
  97.  
  98. add_result = add(num_1, num_2)
  99. logger.info('Add: {} + {} = {}'.format(num_1, num_2, add_result))
  100.  
  101. sub_result = subtract(num_1, num_2)
  102. logger.info('Sub: {} - {} = {}'.format(num_1, num_2, sub_result))
  103.  
  104. mul_result = multiply(num_1, num_2)
  105. logger.info('Mul: {} * {} = {}'.format(num_1, num_2, mul_result))
  106.  
  107.  
  108. #div_result = divide(num_1, num_2)
  109. #logger.debug('Div: {} / {} = {}'.format(num_1, num_2, div_result))
  110. '''
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top