carsten at uniqsys.com
Wed Nov 8 22:43:26 CET 2006
On Wed, 2006-11-08 at 12:37 -0800, John Henry wrote:
> I must be very thick. I keep reading about what decorators are and I
> still don't have a good feel about it. See, for example:
> What exactly do I use decorators for?
Decorators are a tool for executing common code when a function is
defined and/or when it's called. This reduces code duplication by
allowing you to factor out commonly performed steps.
If you find yourself writing different functions that share a lot of
setup/teardown code, or if you find yourself doing a lot of repetitive
housekeeping for each function you're defining, decorators eliminate
You've already been given a bunch of different examples, so I won't bore
you with more contrived examples. If none of the examples make you say
"wow, I could use this" and if you don't find yourself writing
repetitive setup/teardown/housekeeping code, you can probably live quite
comfortably without using decorators.
More information about the Python-list