Pages

Python: Printing Class Object

When we try to print a class object, 'print object' will show as the property. If we want to see what we want to print, just use __repr__.

class Foobar():
"""This will create Foobar type object."""
def __init__(self):
print "Foobar object is created."

def __repr__(self):
return "Type what do you want to see here."

a = Foobar()

print a