str behaviour

Igor V. Rafienko igorr at
Thu Mar 1 16:55:07 CET 2001


I was playing around with printing tuples, when I noticed how str
behaves with "compound" types (such as tuples):

>>> class A:
...     def __str__( self ):
...         return "I'm A"
>>> a = A()
>>> t = ( A, a )
>>> str( t )
'(<class __main__.A at 80fd498>, <__main__.A instance at 810f090>)'
>>> str( a )
"I'm A"

I expected str to be called recursively for the constituent types.
But, alas, that did not happen. Am I misunderstanding something or is
it the intended behaviour? If the latter is the case, could someone
elaborate on why this behaviour was chosen?


Besides, meat tends to run away when possible, or fights. Either
response presents behavioral challenges too complex for any existing
		-- Stuart Wilkinson, inventor of the "gastrobot"

More information about the Python-list mailing list