How to use pprint to print an object using the built-in __str__(self) method?

后端 未结 5 1592
说谎
说谎 2021-02-13 16:44

I have a Python script which processes a .txt file which contains report usage information. I\'d like to find a way to cleanly print the attributes of an object using pprint\'s

5条回答
  •  遇见更好的自我
    2021-02-13 17:35

    For pretty-printing objects which contain other objects, etc. pprint is not enough. Try IPython's lib.pretty, which is based on a Ruby module.

    from IPython.lib.pretty import pprint
    pprint(complex_object)
    

提交回复
热议问题