Decorator

Sybren Stuvel sybrenUSE at YOURthirdtower.com.imagination
Fri May 12 03:13:13 EDT 2006


Lad enlightened us with:
> I use Python 2.3.
> I have heard about decorators in Python 2.4.
> What is the decorator useful for?

A whole lot of stuff. I've used them for:
    - Logging all calls to a function, including its arguments.
    - Ensuring there is a database connection before the function is
      called.
    - Casting the arguments to certain types before passing them to
      the function.

And there is much more possible...

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
                                             Frank Zappa



More information about the Python-list mailing list