
July 26, 2007
1:31 a.m.
Josiah Carlson wrote:
It's already possible.
>>> import sys >>> class foo(object): ... def __getattr__(self, clsname): ... return type(clsname, (object,), {}) ... >>> sys.modules['loader'] = foo()
Yes, that's the sort of ugly hack I was talking about (although mine was slightly worse, involving a module replacing itself with a subclass of module and then re-importing itself). I keep thinking there ought to be a neater way, although I haven't figured out exactly what it should look like. -- Greg