Callable modules?
Peter Hansen
peter at engcorp.com
Tue Jul 23 22:16:34 EDT 2002
Huaiyu Zhu wrote:
>
> Peter Hansen <peter at engcorp.com> wrote:
> >Paul Rubin wrote:
[about putting __call__ in modules]
> >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.
You can make them as similar to other objects as you wish, but it wouldn't
change my opinion that "module" refers to a specific *kind* of object for
which the __call__ convention has little or no merit. I'm not saying it
should not be there, just that it should not be used if it is. :-)
-Peter
More information about the Python-list
mailing list