I tried pprint
from pprint
, but its output is just one line, there is no multiline output and no indentation.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
I use the builtin function
vars
to get the namedtuple as a dictionary.However, it returns an
OrderedDict
whichpprint
won't indent, so I convert it to adict
:With
pprint
anddict
:The pprint PrettyPrinter in Python 3 is much more extendable than it used to be in Python 2. You could create your own printer like below to add methods for the object you want to handle without messing too much with pprint "private" methods and attributes.
You can see an online example here: https://repl.it/HkDd/1
and use it like so:
outputs