json - Inconsistent printing of nested dict using pprint in Python -
i used pprint
pretty print large nested dict
:
import pprint import json open('config.json', 'r') fp: conf = fp.read() pprint.pprint(json.loads(conf)) {u'cust1': {u'videotron': {u'temperature': u'3000k', u'image_file': u'bloup.raw', u'light_intensity': u'20', u'size': [1920, 1080], u'patches': [[94, 19, 247, 77], [227, 77, 293, 232], [77, 217, 230, 279], [30, 66, 93, 211]]}}, u'cust2': {u'rogers': {u'accuracy': true, u'bleed': true, u'patches': [[192, 126, 10, 80], [318, 126, 10, 80], ...
the 2nd level list cust2.rogers.patches
unfold whereas cust1.videotron.patches
not. i'd both not unfold, i.e. printed on same line. know how?
you can play 2 parameters: width
, compact
(the last 1 may not available python 2).
width
-- limits horizontal space.
and here description compact
:
if compact false (the default) each item of long sequence formatted on separate line. if compact true, many items fit within width formatted on each output line.
but understand can't tell pprint
structure of data , how want specific elements printed.
wiki
Comments
Post a Comment