classes are objects... so how can we custom print them: we need a classmethod syntax

Mike C. Fletcher mcfletch at
Fri Aug 20 20:36:08 CEST 2004

 From my metaclasses presentation:

"""Simple example of changing class repr"""
class Meta( type ):
    def __repr__( cls ):
        return '<OhLookAMetaClass>'
class X:
    __metaclass__ = Meta
# this uses the meta-property for lookup
assert repr(X) == '<OhLookAMetaClass>'

Code and presentation available at:


Neil Zanella wrote:

>In Python, classes are objects. But there is no way to custom print a class
>object. This would require some syntax such as the one commented out below:
>With the current "foo = classmethod(foo)" mechanism custom printing for
>class objects is not possible.
  Mike C. Fletcher
  Designer, VR Plumber, Coder

More information about the Python-list mailing list