I have a dictionary which holds objects in its values. I would like to use the str
function on the dictionary, so that it will recursively run on all the other objects in the dictionary.
For instance, I have the following object:
>>> class Temp(object):
... def __init__(self):
... self._item = 8
... def __str__(self):
... return str(self._item)
...
>>> t = Temp()
>>> str(t)
'8'
I create a dictionary and put the object in it:
>>> dict = {}
>>> dict['object'] = t
Now, when I use the str function on the dictionary I get the following:
>>> str(dict)
"{'object': <__main__.Temp object at 0x7fa08889f910>}"
But I would like to get this:
>>> str(dict)
"{'object': 8}"