
Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
Josiah Carlson wrote:
I would really like to see a *sane* use-case for the potential feature
I would like to have some reasonable way of achieving the effect of a __getattr__ for a module, so that I could implement auto-loaded classes.
You can do this now, but the convolutions required are horrible to behold.
I don't think this particular proposal is the way to go about it, though.
It's already possible. >>> import sys >>> class foo(object): ... def __getattr__(self, clsname): ... return type(clsname, (object,), {}) ... >>> sys.modules['loader'] = foo() >>> from loader import bar >>> bar <class '__main__.bar'> >>> import loader >>> loader.boo <class '__main__.boo'> >>> - Josiah