Decorator

Martin Blume mblume at socha.net
Fri May 12 14:01:32 EDT 2006


"bruno at modulix"  schrieb 
> > 
> > Well, if you're changing the original module,
> Who's talking about "changing the original module" ?
> 
Well, you have to apply @deco in the module where
func_to_decorated is placed.

>
> > Isn't the point of a decorator to change the 
> > behavior externally, at runtime, possibly changing
> > it in different ways at different places at 
> > different times?
> 
> You're confusing the python specific @decorator 
> syntax with the OO design pattern by the same name. 
> This syntax is purely syntactic sugar
> for a specific use case of higher order functions.
>
Yes, that explains my confusion.

> 
> > So why this @deco notation? 
> 
> To improve readability.
> 
> @decorator
> def my_one_hundred_locs_func():
>   ...
> 
> is much more readable than:
> def my_one_hundred_locs_func():
>   ...
>   # 100 LOCS later
> my_one_hundred_locs_func = decorator (my_one_hundred_locs_func)
>
That makes sense.

> 
> Note that all this should be clear for anyone having 
> read the doc...
> 
<blush>
Errm, yes, you're so right.

Thanks for reading the documentation to me 
and clearing this up :-)

Martin





More information about the Python-list mailing list