Metaclasses vs. standard Python reflection?

Alex Martelli aleax at aleax.it
Tue May 6 15:55:44 EDT 2003


Dave Benjamin wrote:
   ...
> I managed to bind "object" this way - is this how you would do it?:
> simple.object = simple.__metaclass__('object', (), {})

Actually, I generally use the class statement (when feasible) to
generate classes (just as I almost invariably use def to generate
functions) -- I think that's most readable.  So, I'd do a one-two...:

class object: __metaclass__ = simple.__metaclass__
simple.object = object

but your approach is terser and also quite clear.

> It also assumes you're only applying a single aspect, "Logger" in this
> case. To apply multiple aspects, it would probably be a good idea to have 
a
> single metaclass that dispatches...

Oh yes -- metaclasses must not be multiplied beyond necessity!


> Well, that was very helpful. Thanks for taking the time to answer that. =)

You're welcome!


Alex





More information about the Python-list mailing list