I know
__str__
works for most uses of strings.
But what about when I simply write the instance and press enter in the interpreter?
Currently it returns something like <__main__.class at 0xaea0080>, what method do I use to overwrite that?
I know
__str__
works for most uses of strings.
But what about when I simply write the instance and press enter in the interpreter?
Currently it returns something like <__main__.class at 0xaea0080>, what method do I use to overwrite that?
Use __repr__. Note also that if __str__ is not specified, it defaults to __repr__, but it's rare for this to be useful if you're using them right.
It's a common convention is that __repr__'s result should either look like a constructor call or be surrouned with <>, but it is not intended to be eval'ed in either case.
Lots of better examples here: Difference between __str__ and __repr__ in Python