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

后端 未结 5 1604
说谎
说谎 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:24

    I think beeprint is what you need.

    Just pip install beeprint and change your code to:

    def __str__(self):
        from beeprint import pp
        return pp(self, output=False)
    

提交回复
热议问题