Callable modules?

Huaiyu Zhu huaiyu at gauss.almadan.ibm.com
Tue Jul 23 12:52:19 EDT 2002


Peter Hansen <peter at engcorp.com> wrote:
>Paul Rubin wrote:
>> 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.
>
>Although you can do as you wish, of course, I want to chime in
>with a "this is a really bad idea" and hope you don't follow through
>on it.  This is, even in the best case, going to make your code 
>less readable to anyone else.  It is also likely to cause maintainability
>problems because making the claim "but this module has only one function!"
>almost certainly means it will not stay that way forever.

Why is this so?  Modules appear to be just singletons associated with files.
Why making them more similar to other objects would make programs less
readable?  Maybe some examples of usage would help to clarify the issues.
As a counterexample, I've been confused many times by 'from foo import foo',
not knowing which foo is which.

Huaiyu



More information about the Python-list mailing list