Decorators in Python <hackeve>

Ever used Flask and wondered what the @route nonsense is all about?

Drum roll
More drum rolls

Enter decorators.
A decorator is a function which takes another function as an argument, does some work around it, and returns a new function.
Let's look at a standard decorator.

def home():  
    # some stuff

This is just syntactic sugar for

def home():  
    # some stuff
home = login_required(home)  

Don't worry, we'll start with how functions in Python work, and build on that. We will then make our own decorators, by the end, hopefully, we will build a nano framework (รก la Flask, except more micro).

What do you need?
  • A running Python shell
  • Nothing else.

We'll start at 6PM on Wednesday, October 28, in C01.

UPDATE: Here is the ipython notebook made during the hackeve - html, pdf