Changing the repr() of a class?

Lulu of the Lotus-Eaters mertz at gnosis.cx
Thu Apr 18 16:40:56 EDT 2002


Alex Martelli <aleax at aleax.it> wrote previously:
|class FunkyReprMeta(type):
|    def __repr__(cls):
|        return "My wonderful class %s" % cls.__name__
|class FunkyReprObject:
|    __metaclass__ = FunkyReprMeta
|class C(FunkyReprObject):
|    "whatever you want here"

I don't really understand what a metaclass buys you here.  I think I
might be missing something important, since Alex proposes it.

However, it appears that one could simply define the __repr__ method in
the regular class FunkyReprObject, ignore metaclasses altogether, and
wind up with the same results.  What is better about Alex' approach?

Yours, Lulu...

--
 mertz@   _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i
gnosis  _/_/                    Postmodern Enterprises         _/_/  s r
.cx    _/_/  MAKERS OF CHAOS....                              _/_/   i u
      _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/    g s






More information about the Python-list mailing list