[IPython-dev] Apropos for Python

Gregory Novak novak at ucolick.org
Tue Dec 19 19:15:20 EST 2006


This seems like something that surely someone has written, but I
couldn't find it so away I went...

I was trying to find a variable to check to see whether or not IPython
had been loaded with the -pylab option.  Emacs has nice apropos,
apropos-variable, apropos-function, and apropos-documentation
functions.  I sought to emulate them in Python.  Attached is what I
came up with.

A call like apropos_name("pylab", IPython) will look for any attribute
with pylab in its name (through dir(IPython)).  Then it'll recursively
search through any compound objects available through IPython, etc.  

It keeps a list of the ids of the objects it has already searched, so
it doens't waste (too much) time and circular references shouldn't be
a problem.  

There's also apropos_value (searching the string representation of
objects), apropos_doc, (searching docstrings), apropos_name_regexp,
apropos_value_regexp, and apropos_doc_regexp.  Finally, there's plain
old apropos() that allows you to specify a function that looks for and
searches the bit of the object you care about.

So there it is.  Comments and feedback welcome.  The very likely
comment "That's nice and all, but you should be using
super-py-apropos-deluxe that everyone else uses and is 100x better" is
welcome, too.

By the way, the call apropos_name('pylab', IPython) led me to:

IPython.ConfigLoader.ultraTB.pydoc.__builtin__._ip.options.pylab
and
IPython.ConfigLoader.ultraTB.pydoc.__builtin__._ip.options.opts.pylab

Is that really where I have to look to find out whether or not IPython
was started with the pylab option?  That's even more buried than I
thought it would be.

Cheers,
Greg

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: apropos.py
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20061219/3223c3e6/attachment.ksh>


More information about the IPython-dev mailing list