Steven D'Aprano wrote: > On Wed, 08 Feb 2006 13:58:13 +1100, Delaney, Timothy (Tim) wrote: > > > adam johnson wrote: > > > >> Hi All. > >> I was wondering why defining a __call__ attribute for a module > >> doesn't make it actually callable. > > > > For the same reason that the following doesn't work > [snip example] > > The __call__ attribute must be defined on the class (or type) - not on > > the instance. A module is an instance of <type 'module'>. > > That's not a _reason_, it is just a (re-)statement of fact. We know that > defining a __call__ method on a module doesn't make it callable. Why not? > The answer isn't "because defining a __call__ method on a module or an > instance doesn't make it callable", that's just avoiding the question. > > Someone had to code Python so that it raised an error when you try to call > a module object. Is there a reason why module() should not execute > module.__call__()? I would have thought that by the duck typing principle, > it shouldn't matter whether the object was a class, a module or an int, if > it has a __call__ method it should be callable. >
It would nice if you could make modules callable. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml > > -- > Steven. -- http://mail.python.org/mailman/listinfo/python-list