Using Rich Inspect to Interrogate Python Objects
Using Rich Inspect to Interrogate Python Objects
November 13, 2022·Christopher Tyler,Will McGugan
Will McGugan’s article goes through another way Rich can help with formatting. The rest of the article are my notes.
If you invoke it with any object inspect
will display a nicely formatted
report on that object – which makes it great for interrogating objects from
the REPL.
>>> from rich import inspect
>>> text_file = open("foo.txt", "w")
>>> inspect(text_file)
By default, inspect
will generate a data-oriented summary with a text
representation of the object and its data attributes.
You can also add methods=True
to show all the methods in the public API.
Also if you want to see the full unabbreviated help you can add help=True
.
Finally there are few more arguments to refine the level of detail you need. You can see the full range of options with this delightful little incantation:
>>> inspect(inspect)