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: >>> doc("*inv") numpy.linalg.inv numpy.linalg.pinv numpy.linalg.tensorinv 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. Cheers, Joris --------------------------- import numpy from inspect import getdoc import re def doc(searchstr): 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[0] != '_'] 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: print results[0] mod = numpy components = results[0].split('.') for comp in components[1:]: mod = getattr(mod, comp) docstring = getdoc(mod) if docstring is not None: print docstring else: print results[0] + " exists, but no docstring was found" else: for s in results: print s Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion