Callable modules?

Paul Rubin phr-n2002b at NOSPAMnightsong.com
Mon Jul 22 13:33:16 EDT 2002


Stefan Schwarzer <sschwarzer at sschwarzer.net> writes:
> > Just to not have to say "foo.foo()" or "from foo import foo".
> > If the main purpose of the module is to provide one function, I think
> > it's cleaner to be able to import the module and call the function
> > without special tricks.
> 
> I consider it cleaner to be explicit, and import the module and call
> its function. :-)

Does that reasoning not also apply to class instances?  Why should
class instances be callable through the __call__ method?

> How many actual cases do you know of where a module has a single function?
> Aren't they rare?

I've written several, there are several in the Python library, and
remember that it's not necessary for the module to have a single
function for a __call__ interface to be useful.  __call__ makes sense
if there's a most-important or most-frequently-used function in the
module.  It's ok if there are other functions too.



More information about the Python-list mailing list