I tried pprint
from pprint
, but its output is just one line, there is no multiline output and no indentation.
I use the builtin function vars
to get the namedtuple as a dictionary.
However, it returns an OrderedDict
which pprint
won't indent, so I convert it to a dict
:
>>> from collections import namedtuple
>>> Busbar = namedtuple('Busbar', 'id name voltage')
>>> busbar = Busbar(id=102, name='FACTORY', voltage=21.8)
With pprint
and dict
:
>>> from pprint import pprint
>>> pprint(dict(vars(busbar)))
{'id': 102,
'name': 'FACTORY',
'voltage': 21.8}