metaclasses vs. inheritance

Aldo Cortesi aldo at
Fri Jun 28 06:04:22 EDT 2002

Thus spake Ian McMeans (imcmeans at

> Can someone give an example of a problem that is solved
> with metaclasses, which would be difficult or impossible
> to solve with inheritance?

There are some things that can only be done with metaclasses
- changing the text representation of a class, for instance.

class Extended(type):
    def __repr__(self):
        attrs = []
        for i in dir(self):
            attrs.append("%-20s\t\t%s" % (i, type(self.__getattribute__(self, i))))
        return "%s:\n\t%s" % (type.__repr__(self), "\n\t".join(attrs))
class Foo(object): 
    __metaclass__ = Extended
print Foo

Baroque, I know, but it illustrates the point. 

> PS - what's the antonym of meta?

Hmmm... the meta- in "metaclass" or "metaphysics" really has
no relation to the original Greek, which means "with", or
"among" (as in "metatarsus" - the bones in the foot which
lie next to the tarsus). So whatever antonym you come up
with can't have anything to do with the original etymology
of the prefix...  Erm... How about mundane? Or actual?
Intrinsic? Essential? Or even "per se"....?



Aldo Cortesi
aldo at

More information about the Python-list mailing list