Guido van Rossum wrote: >>class X(object): >> def __str__(self): >> return 'str for X' >> >> def __repr__(self): >> return 'repr for X' >> >>class A(X): >> def __repr__(self): >> return 'repr for A' >> >># __str__ = __repr__ > > This has never been different and the current outcome is exactly what > was intended. The only case where __repr__ and __str__ act as each > other's default is when there's no base class. The OP's example also shows how easy it is to create a class which returns the same thing for str(foo) and repr(foo). Simply write one of either __repr__ or __str__ and then assign the same function to the other one. Regards, Nick. -- Nick Coghlan | Brisbane, Australia Email: ncoghlan at email.com | Mobile: +61 409 573 268
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4