__str__ vs. __repr__
Tim Peters
tim_one at email.msn.com
Wed Nov 10 01:39:13 EST 1999
[Toby Dickenson:]
> 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.
[Jeremy Hylton]
> 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
mailing list