[omaha] Decorators

Jeff Hinrichs - DM&T jeffh at dundeemt.com
Tue Jan 15 04:11:00 CET 2008


To add to my prematurely sent email from above<g>:

Decorators in python are syntactic sugar to let you wrap a
function/method with another function.  While possible, to a
degree(ease), before the implementation of pep 318
http://www.python.org/dev/peps/pep-0318/ the pep standardizes the
idiom and created a new syntactic element, '@'.

The decorator module that Eli has been experimenting with is itself a
decorator.  Its purpose is to preserve the function signature of a
function that has been decorated.  If you check out the docs for the
module by Michelle Simionato,
http://www.phyast.pitt.edu/~micheles/python/documentation.html  you'll
get a feel for why the function signature might be meaningful to you
or tools that you use.   I would strongly recommend taking a read as
the decorator module has some nice side effects.   Read it through to
the end as this document talks about the downside of decorators too.

-j

On 1/14/08, Jay Hannah <jay at jays.net> wrote:
> On Jan 14, 2008, at 4:40 PM, Matthew Nuzum wrote:
> > 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.
>
> http://en.wikipedia.org/wiki/Decorator_pattern
>
> http://en.wikipedia.org/wiki/Python_syntax_and_semantics#Decorators
>
> My favorite design patterns book:
>
> http://www.oreilly.com/catalog/hfdesignpat/
>
> As luck would have it, the free sample chapter just happens to be on
> the Decorator Pattern:
>
> http://www.oreilly.com/catalog/hfdesignpat/chapter/ch03.pdf
>
> (I never felt good about any Decorator Pattern I tried in Perl (years
> ago).  -grin-)
>
> j
>
>
> _______________________________________________
> Omaha Python Users Group mailing list
> Omaha at python.org
> http://mail.python.org/mailman/listinfo/omaha
> http://www.OmahaPython.org
>


-- 
Jeff Hinrichs
Dundee Media & Technology, Inc
jeffh at dundeemt.com
402.218.1473


More information about the Omaha mailing list