Is it possible in python to change what is printed for classes. I know that if we provide __str__
__unicode__
methods, we can change the way instances of a class are printed. But i want to do this for a class
Eg:
class A(object):
def __str__(self):
return 'hello'
a = A()
print a
will print hello
. Is it possible to change the behaviour of print A
which by default prints something like <class '__main__.A'>
Update: I guess i might as well explain the context. I am trying to create MySQL queries and i have classes representing tables. Each of these table-classes have a class variable containing the table name. So what i want to do is to be able to pass the Class as parameter to cursor.execute and have the tablenames substituted in the query.