<div class="gmail_quote">On Tue, Apr 13, 2010 at 4:36 PM, Conrad Irwin <span dir="ltr"><<a href="mailto:conrad.irwin@googlemail.com">conrad.irwin@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
A common pattern when creating decorators is something of the form:<br>
<br>
def decorator(func):<br>
def wrapper(*args):<br>
func(modulate(args))<br>
return wrapper<br></blockquote><div><br>You might be interested in Michele Simionato's excellent decorator
package. The above could be written:<br><br>import decorator<br>def my_decorator(func):<br> return decorator.decorator(func, lambda: func(modulate(args)))<br><br>If your pattern is very common, you could even create your own meta-decorator, like this:<br>
<br>def args_modulator(func, modulator):<br> return decorator.decorator(func, lambda: func(modulator(args)))<br><br>It's available on PyPi: <a href="http://pypi.python.org/pypi/decorator">http://pypi.python.org/pypi/decorator</a><br>
<br>In a nutshell, whatever part of your pattern is common, abstract out.<br></div></div><div style="margin: 2em 0pt;" name="sig_2341e11ee1">--<br>
Daniel Stutzbach, Ph.D.<br>
President, <a href="http://stutzbachenterprises.com">Stutzbach Enterprises, LLC</a>
</div>