what's the use of __repr__?when shall I use it?

Vikram vvikram at stanford.edu
Fri Apr 1 02:16:19 EST 2005


__repr__ should return something that when eval'ed yields an identical
object (if possible). essentially it should represent the programmer/debug
view of the object.

__str__ should mostly return a highly user-friendly string (note: str(obj)
will use __repr__ if __str__ doesn't exist)

you might also be interested in this thread covering the same topic:
http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/d10731049459726f/2a8f62f478057abd?q=python+__repr__+__str__+difference&rnum=6#2a8f62f478057abd

thanks,
			Vikram




More information about the Python-list mailing list