background preloader

Decorator

Facebook Twitter

Cookbook

Metaprogramming. The decorator module. This version is obsolete: go to for the latest version Python 2.4 decorators are an interesting example of why syntactic sugar matters: in principle, their introduction changed nothing, since they do not provide any new functionality which was not already present in the language; in practice, their introduction has significantly changed the way we structure our programs in Python.

The decorator module

I believe the change is for the best, and that decorators are a great idea since: decorators help reducing boilerplate code;decorators help separation of concerns;decorators enhance readability and maintenability;decorators are very explicit. Still, as of now, writing custom decorators correctly requires some experience and it is not as easy as it could be.