python newbie

Duncan Booth duncan.booth at invalid.invalid
Mon Nov 5 10:06:05 CET 2007

Steven D'Aprano <steve at> wrote:

> As far as I know, all it would take to allow modules to be callable
> would be a single change to the module type, the equivalent of:
> def __call__(self, *args, **kwargs):
>     try:
>         # Special methods are retrieved from the class, not
>         # from the instance, so we need to see if the 
>         # instance has the right method.
>         callable = self.__dict__['__call__']
>     except KeyError:
>         return None # or raise an exception?
>     return callable(self, *args, **kwargs)

The error should throw "TypeError: 'module' object is not callable" just as 
it does today.

Also, it shouldn't pass self through to callable: modules have functions 
not methods.

More information about the Python-list mailing list