
June 30, 2011
3:34 p.m.
On Thu, Jun 30, 2011 at 9:38 PM, Sturla Molden <sturla@molden.no> wrote:
Often when exploring an object with the 'dir' function, particularly in large packages like SciPy, I find that I need to filter the outout. Since a dir reminds me of a dos 'dir' or linux 'ls', a glob feels like the most natural to use.
For example, none of these would work:
dir(sp.fft.i*) # syntax error dir('sp.fft.i*') # returns the attributes a string
import fnmatch def glob_dir(obj, pattern): return fnmatch.filter(dir(obj), pattern)
print(glob_dir(str, "c*")) ['capitalize', 'center', 'count']
If it's something you use often, drop it into a utility module or PYTHONSTARTUP Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia