Getting started with using decorators in Python 3.7 using this quick guide
Got inspired at itDAGENE 2018 when Equinor held a short course on how to use Decorators in Python.
def display():
print('Display function executed ... \n')
decorated_display = decorator_func(display)
decorated_display()
# ... is EQUIVALENT with ...
@decorator_func # This is where the magic happens
def display():
print('Display function executed ... \n')
@my_logger
@my_timer
def display_info(name, age):
print('display_info ran with arguments ({}, {})'.format(name, age))
# ... is EQUIVALENT with ...
def display_info(name, age):
print('display_info ran with arguments ({}, {})'.format(name, age))
display_info = my_logger(my_timer(display_info))