how to use __str__ and __repr__?

Jim Newton jimka at rdrop.com
Tue Jun 8 02:08:04 EDT 2004


if that is the case then why does the following fail

class another:
	pass

another.__str__()

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
>>class().__str__()?
>>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