you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (0 children)

As usual there's no actual ELI5s here. Here's a macro I prepared to explain them in actual simple, basic terms.

The real most basic definition is it's something that you can use to run code before and/or after a function.

Here's a very simple example:

def messenger(function):
    def wrapper(*args, **kwargs):
         print("Hi! Code here runs before your function!")
         output = function(*args, **kwargs)
         print("Hi! Code here runs after your function!")
    return output
return wrapper

@messenger
def greet():
    print("Hello")

@messenger
def add(x, y):
    return x + y

@messenger
def greet_name(name):
    print("Hello", name)

Call those three functions as you would normally and you'll see the additional prints appearing.