classes are objects... so how can we custom print them: we need a classmethod syntax
nzanella at cs.mun.ca
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.
#def classmethod __str__(cls):
# return "pythons bite"
foo = Foo()
s = "hello %s!" % foo # custom text here
print Foo # no custom text here possible it seems, unless we call
# a staticmethod such as Foo.printMe()
More information about the Python-list