Decorator to inject function into __call__ of a class

Patrick Maupin pmaupin at gmail.com
Sat Mar 13 17:26:15 CET 2010


On Mar 13, 10:19 am, Jon Clements <jon... at googlemail.com> wrote:

> What I'd like to achieve is something similar to:
>
> @inject(B):
>  def some_function(a, b):
>      pass # something useful

So, just typing at the keyboard here, you mean something like:

class InjectClass(object):
    def __init__(self, func, *args, **kw):
        self.func = func
        self.args = args
        self.kw = kw
    def __call__(self):
        self.func(*self.args, **self.kw)

Or exactly what are you looking for?

Pat



More information about the Python-list mailing list