I am getting familiar with decorators, and after a couple of tutorials i came up with a decorator that might is useful for me. Is this the proper way to use decorators? Any suggestion about the code?def timeit_decorator(original_function):    import time    import colorama    def wrapper(*args, **kwargs):        tm = time.time()        res = original_function(*args, **kwargs)        print(Function  + colorama.Fore.GREEN + original_function.__name__ + colorama.Style.RESET_ALL +  executed in  + colorama.Fore.GREEN + ~{:.2f}.format(            (time.time() - tm) / 60) + colorama.Style.RESET_ALL +  minutes!)        return res    return wrapperExample of usage:@timeit_decoratordef display(msg):    time.sleep(10)    return msgprint(display(1))
First touch with python decorator
python;python 3.x
When using decorators, you should familiarize yourself with functools.wraps. Consider the difference in available informations between these two (useless) decorators:from functools import wrapsdef decorate1(func):    def wrapper(*args, **kwargs):        return func(*args, **kwargs)    return wrapperdef decorate2(func):    @wraps(func)    def wrapper(*args, **kwargs):        return func(*args, **kwargs)    return wrapperWhen applied to a function:@decorate1def test1(x, y, z):    test1 docstring    print(x, y, z)@decorate2def test2(x, y, z):    test2 docstring    print(x, y, z)The help on each function look quite different:>>> help(test1)Help on function wrapper in module __main__:wrapper(*args, **kwargs)>>> help(test2)Help on function test2 in module __main__:test2(x, y, z)    test2 docstringSince youre using Python 3, you should consider using better timing primitives. Namely time.perf_counter():def wrapper(*args, **kwargs):    begin = time.perf_counter()    res = original_function(*args, **kwargs)    elapsed = time.perf_counter() - beginLastly, you should consider using format all along instead of string concatenation:import timeimport coloramafrom functools import wrapsdef timeit_decorator(original_function):    @wraps(original_function)    def wrapper(*args, **kwargs):        begin = time.perf_counter()        result = original_function(*args, **kwargs)        elapsed = time.perf_counter() - begin        print(Function {color}{}{reset} executed in {color}              ~{:.2f}{reset} minutes!              .format(                  original_function.__name__,                  elapsed / 60,                  color=colorama.Fore.GREEN,                  reset=colorama.Style.RESET_ALL))        return result    return wrapper