[Python-ideas] Modules could behave like new-style objects

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Apr 3 08:41:49 CEST 2009


Zac Burns wrote:
> On Thu, Apr 2, 2009 at 2:23 PM, Aahz <aahz at pythoncraft.com> wrote:
> 
>>Guido can speak up for himself, but in the past he's been pretty negative
>>about this idea; you may want to hunt up previous threads.

I think the basic objection is that it would be
inconsistent, because __getattr__ et al only have
effect when defined in the object's class, not the
object itself, and modules are not classes.

What might be workable is a way to specify the class
you want a module to have, something like

__moduleclass__ = MyFancyModule

But that doesn't quite work, because it needs to get
evaluated before creating the module object, but
you need to execute the module code first so you can
import MyFancyModule from somewhere... it all gets
rather messy.

-- 
Greg



More information about the Python-ideas mailing list