how to use __str__ and __repr__?
Erik Max Francis
max at alcyone.com
Mon Jun 7 19:50:46 EDT 2004
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?
--
__ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
\__/ Whoever contends with the great sheds his own blood.
-- Sa'di
More information about the Python-list
mailing list