[Tutor] decorators -- treat me like i'm 6.. what are they.. why are they?

Alan Gauld alan.gauld at yahoo.co.uk
Wed Jul 6 17:34:47 EDT 2016

On 06/07/16 20:35, bruce wrote:

> Saw the decorator thread earlier.. didn't want to pollute it. I know, I
> could google!
> But, what are decorators, why are decorators? who decided you needed them!

decorators are things that modify functions in standard ways.
Specifically they are functions that act on functions.
Mostly people think of them as being the thing that comes after an @
sign, but in fact they are just functions but with a bit of syntactic
sugar to make them more readable.

You don't really *need* them as a feature, but if you have
the ability to treat functions as values they are a useful

Most Python programmers don't implement decorators they just
use the standard ones. But as the thread showed implementing
them is not too difficult once you get happy with the idea
of passing functions around as arguments to other functions.

As to who suggested them you'd need to go back through the
PEPs to see who first suggested it, and then maybe more to see
who's idea finally got accepted. I think it was in Python 2.5.

Alan G
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:

More information about the Tutor mailing list