__str__ vs. __repr__
tim_one at email.msn.com
Wed Nov 10 07:39:13 CET 1999
> Tim's Rat class is a good example of how __repr__ should not be
> implemented, because it exposes the internal representation of
> the object, not the external value.
[Rat's Tim class]
> Beg to differ: it's an excellent example of how __repr__ should
> be implemented.
> It's no accident that the function is called __repr__. It's role is
> to expose the representation.
No, in that case it would have been named __representation__. __repr__ is
actually an acronym, meaning Regular-Expression Parsable Rendition.
Similarly __str__ is short for Simpler Than Repr. I never learned what
__init__ stands for -- it never interested Tim <wink>.
guess-what-wink-stands-for-and-win-a-fabulous-prize!-ly y'rs - tim
More information about the Python-list