[IPython-User] A few magic commands useful for object inspection
Thu Mar 28 18:15:33 CDT 2013
I packaged up some code I've been using myself for a long time to find or
inspect objects within IPython. The implementation is totally independent
of IPython (so anyone can use it) but I've provided magic commands to make
it especially convenient to use within IPython.
You can download releases from the PyPI page:
and the source code is on Launchpad:
You use it just by saying 'import grasp' and it registers the magic commands
There are three main commands:
* gist -- what is the present object all about? Present information about
all of the attributes of an object, organized by type. So all of the
attributes that are integers are listed together, all methods are listed
together, etc. I find this very useful when confronted with an unfamiliar
object and I'm asking "what kind of information does it contain? What
kinds of things can it do?"
* rtype -- recursive type. Take a list, tuple, dict, or other container
class and recursively descend through its contents, collecting type
information. Try to concisely convey the structure of the object. So this
will tell you that (1,2,3) is a "tuple of 3 ints" and ( [1,2], [3,4], [5,6]
) is a "tuple of 3 (list of 2 ints)"
* apropos -- deep search of modules (or the global namespace) for objects
with a given name, value, or docstring contents. Suppose I know that
IPython allows me to set the color scheme, to "Linux", "LightBG", or
whatever. But I have no idea where within the IPython module to find the
setting. I can type "%apropos colors IPython" and apropos will search
through the IPython module, all submodules, all of _their_ submodules, etc,
and return a list of places I should poke around to learn more about how
IPython handles colors.
Apropos is similar to the %psearch function, but I believe the %psearch
function only searches one namespace at a time -- it doesn't recurse. So
you can do things like "%psearch IPython.colors*" or "%psearch
IPython.*.colors" but you can't have it recursively search all submodules.
Also, Apropos is more flexible in allowing you to search for things by
name, value, docstring, equality, etc.
Enjoy, and feedback is welcome.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the IPython-User