how to use __str__ and __repr__?

Jim Newton jimka at
Tue Jun 8 08:08:04 CEST 2004

if that is the case then why does the following fail

class another:


I would think that would return a string such as
"<__main__.another instance at 0x8132b64>"
but it does not seem to.

Erik Max Francis wrote:
> Jim Newton wrote:
>>thanks for responding,
>>i was expecting class().__str__()
>>to evaluate to the string "<__main__.another instance at 0x8132b64>"
>>because that what print does with class().
>>but alas it does not.
>>why does print class() not give me the same error as
>>that's what i do not understand.
> In the example you gave, your class is derived from list, so it uses
> list.__str__.  It's doing exactly what an object-oriented system should
> do; defer to the base class.  Why do you think that's wrong?

More information about the Python-list mailing list