how to use __str__ and __repr__?
Jim Newton
jimka at rdrop.com
Tue Jun 8 11:25:49 EDT 2004
wow that works...
def __repr__(self):
middle = " ".join( [ str(substr) for substr in self])
return "( " + middle + " )"
thanks
-jim
Carl Banks wrote:
> Carl Banks wrote:
>
>>
>>Jim Newton wrote:
>>
>>>hmm, even when i change it to calling str() rather than __str__()
>>>it does not work.
>>>
>>>class another:
>>> pass
>>>
>>>print another() # works
>>>another().str() # does not work
>>>
>>>does anyone know why?
>>
>>str is a function, not a method.
>
>
> (Ok, it's actually a type object.)
>
>
More information about the Python-list
mailing list