[Python-ideas] of properties and metaclasses

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Jul 26 03:31:35 CEST 2007


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



More information about the Python-ideas mailing list