__call__ considered harmful or indispensable?

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Thu Aug 2 10:33:13 EDT 2007


Paul Rubin a écrit :
> skip at pobox.com writes:
> 
>>In this particular case it was clearly unnecessary and just obfuscated the
>>code.  I'm wondering, are there some general cases where __call__ methods of
>>a user-defined class are simply indispensable?
> 
> 
> I don't know about "indispensable" but __call__ is convenient sometimes
> and I do use it.  I've wished that modules supported call, so I could
> say
> 
>     import foo
>     x = foo(3)
> 
> instead of having to say x=foo.foo(3) or something like that.

from foo import foo
x = foo(3)

Or did I miss the point ???



More information about the Python-list mailing list