Monday, December 27, 2010

change class (not instance) __repr__ with metaclass

>>> class PrintMeta(type):
...    def __repr__(cls):
...       return "Hello World!"
...
>>> class A(object):
...    __metaclass__ = PrintMeta
...
>>> A
Hello World!

No comments:

Post a Comment