3 ms·
An extremely useful hidden gem in Rich is its `inspect` function [1]. When called on an object, it pretty prints a list of its public attributes (though you ca
by pedrovhb 5y ago
An extremely useful hidden gem in Rich is its `inspect` function [1].
When called on an object, it pretty prints a list of its public attributes (though you can also request private and dunder attributes) [2]. It can also be called on a class or function; it'll then pretty print the docstrings, parameters with types, methods, etc. It's great for debugging and for starting to code with libraries you're not familiar with, don't have comprehensive documentation, or have some dynamic aspect.
In a similar vein, `objexplore` [3] is another library that lets you dive into an object's nested attributes to understand how it's laid out.
In interactive debugging sessions I often find these to be more useful than the IDE's features which provide similar functionality.
[1] https://rich.readthedocs.io/en/stable/reference/init.html#rich.inspect https://rich.readthedocs.io/en/stable/reference/init.html#ri...
[2] https://i2.paste.pics/798cff2903f6b3351289a24c839d4f44.png https://i2.paste.pics/798cff2903f6b3351289a24c839d4f44.png
[3] https://github.com/kylepollina/objexplore https://github.com/kylepollina/objexplore
- orf 5y agoThe ipython ? Syntax also does this: “some_object?”
- dr_zoidberg 5y agoIPythons ? and tab-autocomplete feel like superpowers when exploring a new module you're unfamiliar with.