str behaviour
Igor V. Rafienko
igorr at ifi.uio.no
Thu Mar 1 10:55:07 EST 2001
Hi,
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?
TIA,
ivr
--
Besides, meat tends to run away when possible, or fights. Either
response presents behavioral challenges too complex for any existing
robot.
-- Stuart Wilkinson, inventor of the "gastrobot"
More information about the Python-list
mailing list