I've read a few introductory books and articles about python now and decided it was time to look for a more advanced book. I've started reading Pro Python by Marty Alchin. It goes into a lot more depth about python. One of the chapters talks a lot about functions and describes several more applications of decorators. Briefly as follows
- A decorator that will suppress any error raised by using a try/except block
- A memoization decorator that "remembers" arguments that a function has been called with in the past and it's corresponding return values. If the decorated function is called with the same arguments again it simply returns the value stored in the cache instead of performing the calculation again.
- A decorator that turns a function into a decorator function! I know, bends your brain a bit doesn't it?
I thoroughly recommend reading this book if you want to learn more about the decorators. If you know any other good uses for decorators please let me know in the comments.