__call__ considered harmful or indispensable?

Paul Boddie paul at boddie.org.uk
Thu Aug 2 18:58:08 EDT 2007


Bruno Desthuilliers wrote:
>
> Most of what you can do with a callable instance can be done with
> closures (and is usually done so in FPLs), but given Python's OO nature,
> it's sometimes clearer and simpler to use callable instances than
> closures.

Indeed. I think __call__ has been neglected as closures have become
more widely used. In all cynicism, however, I'd argue that with
Python's very usable implementation of object-orientation, classes
with __call__ methods frequently make for clearer demonstrations of
solutions than closures do, despite requiring slightly more characters
of source code, and in contrast to the apparent fashion for using
closures for showing off more or less everything these days (despite
various pitfalls which may seem counter-intuitive to the beginner).

Paul




More information about the Python-list mailing list