module not callable - why not?

djw dwelch91 at comcast.net
Fri Apr 9 13:07:05 EDT 2004


Diez B. Roggisch wrote:
> Hi,
> 
> I just thought about creating a module for quaternions (as an personal
> exercise, so I'm not after pointers to classlibs here).
> 
> Now usually I'd create a file called "quaternion.py", define my quaternion
> class in there and then import and create an instance like this:
> 
> import quaternion
> 
> q = quaternion.quaternion()
> 
> Thats a lot to type. doing a 
> 
> from quaternion import quaternion 
> 
> would solve that - but AFAIK thats considered bad for some reasons.

I think what people consider dangerous is 'from <module> import *'. The 
form you give here is OK, as far as I know.

> 
> Now I thought about defining a __call__ operator at module level to allow
> this:
> 
> import quaternion
> 
> q = quaternion()
> 
> 
> where the call looks like this:
> 
> def __call__(*a, *kw):
>     return quaternion()
> 
> But that doesn't work. 
> 
> Now my question is: Is there a way to make a module callable that way? And
> wouldn't it make sense to allow the implementation of a call operator on
> module level?

I know this has been discussed before (using __main__() instead). Try 
googling for some discussions.

-Don




More information about the Python-list mailing list