__call__ considered harmful or indispensable?

James Stroud jstroud at mbi.ucla.edu
Thu Aug 2 21:37:00 EDT 2007


James Stroud wrote:
> import functools
> class enclosable(object):
>   def __init__(self, func):
>     self.func = func
>   def __call__(self, *args, **kwargs):
>     return functools.partial(self.func, *args, **kwargs)
> 
> For example:
> 
> @enclosable
> def do_something_with(a, b):
>   [etc]


On second thought:

def enclosable(func):
   def _f(*args, **kwargs):
     return functools.partial(func, *args, **kwargs)
   return _f

I guess __call__ is not necessary for this decorator after all.

James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/



More information about the Python-list mailing list