Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Decorators

The output is not always the same although it should be!

The order in which my logging.debug line and the code block of multiply_by_five is executed keeps switching. I don't understand the steps that occur when I use '@'. Does the decorator run first, then the code block of function the decorator was put. Because in this case the number 215 should never be outputted to the console before the logging.debug line. Either way, can you explain to me what happens once I call multiply_by_five(43). Thanks :)

def logme(func):
    import logging
    logging.basicConfig(level=logging.DEBUG)

    def inner(*args, **kwargs):
        logging.debug('Called {} with args {} and kwargs {}'.format(func.__name__, args, kwargs))
        return func(*args, **kwargs)

    return inner


@logme
def multiply_by_five(num):
    return num * 5


print(multiply_by_five(43))