how to use __str__ and __repr__?
peter at engcorp.com
Tue Jun 8 00:25:13 CEST 2004
Jim Newton wrote:
> hi all, does anyone know what print does if there is no __str__ method?
From the documentation at http://docs.python.org/ref/customization.html :
Called by the repr() built-in function and by string conversions
(reverse quotes) to compute the ``official'' string representation of an
object. .... 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.
Does that help?
More information about the Python-list