[omaha] Decorators
Matthew Nuzum
newz at bearfruit.org
Mon Jan 14 23:40:44 CET 2008
On 1/14/08, Eli Criffield <elicriffield at gmail.com> wrote:
>
> You can add functionality to any or every method you define without
> having to change that method, just add the decorator.
>
> Here's my simple example.
>
> --snip--
>
> from decorator import decorator
>
> @decorator
> def trace(f, *args, **kw):
> print "call %s with args, %s, %s"%(f.func_name,args,kw)
> return f(*args, **kw)
>
> @trace
> def sum_three(a, b, c):
> return a + b + c
>
> print sum_three(1,2,3)
>
Would you mind explaining what's going on here? I'm not sure what you're
doing. I've heard of decorators but never tried using them.
--
Matthew Nuzum
newz2000 on freenode
More information about the Omaha
mailing list