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

Mike C. Fletcher mcfletch at rogers.com
Fri Aug 20 14:36:08 EDT 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:
    http://www.vrplumber.com/programming/

HTH,
Mike

Neil Zanella wrote:

>Hello,
>
>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
  http://www.vrplumber.com
  http://blog.vrplumber.com




More information about the Python-list mailing list