The docs say that "If a class defines __repr__() but not __str__(), then
__repr__() is also used when an “informal” string representation of
instances of that class is required."
but, repr is ignored:
>>> class E(Exception):
... def __repr__(self):
... return 'fancy!'
...
>>> raise E()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
__main__.E
only str is respected:
>>> class E(Exception):
... def __str__(self):
... return 'fancy!'
...
>>> raise E()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
__main__.E: fancy! |