In Python, the object class serves as the root superclass for all the (new-style) classes. By default at least, applying str and repr
object
str
repr
Here's the new answer for Python 3. Basically, you pass in a metaclass as a keyword parameter to the class definition.
class fancytype(type): def __str__(self): return self.__name__ class ham(metaclass=fancytype): pass print(ham)
prints
ham