[Numpy-discussion] Improving Docs on Wiki
Joris De Ridder
Fri Mar 21 22:17:37 CDT 2008
On 21 Mar 2008, at 18:22, Joe Harrington wrote:
> What you have brought up is really a documentation problem: how do I
> find the name of the routine I want?
One way of dealing with this, could be the implementation of a "doc()"
function in numpy that helps you to find what you want. A (still
fairly basic) version of such a doc() function is given below. It
understands the unix-like wildcards * and ?, and it will also find
numpy classes/functions in the subpackages linalg, fft, and random. If
it finds several possibilities it lists them, if only 1 match is
found, the docstring is immediately given. As an example:
It's should not be difficult to improve doc() by letting it also
search in the docstrings, or by letting it respond intelligently to
some "magic" search terms like e.g. category names.
from inspect import getdoc
searchstr = searchstr.strip().replace('*','\w*').replace('?','\w')
pattern = re.compile('^'+searchstr+'$')
results = 
for package in [numpy, numpy.linalg, numpy.fft, numpy.random]:
searchlist = [a for a in dir(package) if a != '_']
results += [package.__name__ + "." + s for s in searchlist if
pattern.search(s) != None]
if len(results) == 0:
print "Sorry, no matches"
elif len(results) == 1:
mod = numpy
components = results.split('.')
for comp in components[1:]:
mod = getattr(mod, comp)
docstring = getdoc(mod)
if docstring is not None:
print results + " exists, but no docstring was found"
for s in results:
More information about the Numpy-discussion