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

Neil Zanella nzanella at
Fri Aug 20 20:11:08 CEST 2004


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.


class Foo:
  def __str__(self):
    return "foo"
  #def classmethod __str__(cls):
  #  return "pythons bite"

foo = Foo()
s = "hello %s!" % foo # custom text here
print s

print Foo # no custom text here possible it seems, unless we call
          # a staticmethod such as Foo.printMe()



More information about the Python-list mailing list