[Python-ideas] TypeError: 'module' object is not callable

Christian Heimes lists at cheimes.de
Fri Feb 20 18:35:00 CET 2009

Ralf W. Grosse-Kunstleve wrote:
> I see there have been discussion about module __call__ about three years ago:
> http://mail.python.org/pipermail/python-list/2006-February/thread.html#366176
> Is there an existing pronouncement on this subject?
> __call__ would help avoiding strange things like from StringIO import StringIO
> or having to come up with silly names like run, driver, manager, etc.
> Ideally, __call__ could be either a function or class.
> I imagine, nothing special, except that a module object looks for __call__ instead
> of producing a type error.

It's technically not possible without jumping through several loops.
Magic methods are looked up on the class. Modules are instances of the
ModuleType class.


More information about the Python-ideas mailing list