Any way to properly pretty-print ordered dictionaries?

后端 未结 15 1491
春和景丽
春和景丽 2020-12-07 14:34

I like the pprint module in Python. I use it a lot for testing and debugging. I frequently use the width option to make sure the output fits nicely within my terminal window

15条回答
  •  一整个雨季
    2020-12-07 15:02

    You can also use this simplification of the kzh answer:

    pprint(data.items(), indent=4)
    

    It preserves the order and will output almost the same than the webwurst answer (print through json dump).

提交回复
热议问题