gettin a list of functions?
P_spam_ at draigBrady.com
P_spam_ at draigBrady.com
Mon Dec 9 11:47:54 EST 2002
Hunter Peress wrote:
> for a given scope how could i obtain a list of functions/methods.
>
> dir() is too general.
>
> either this will involve parsing the output of dir()
>
> or using the access to the compiler module that I can't figure out.
In addition to the previous suggestions for filtering all functions,
if you want to filter names I find the following useful:
def dire(o, pat=None):
"""like dir, but can filter results with re pat"""
names = dir(o)
if not pat:
return names
import re
pat = re.compile(pat)
def match(name, fn=pat.search):
return fn(name) is not None
return filter(match, names)
def ls(o, pat=None):
"""like dir, but can filter results with glob pat"""
names = dir(o)
if not pat:
return names
import fnmatch
def match(name, fn=fnmatch.fnmatch, pat=pat):
return fn(name, pat)
return filter(match, names)
Pádraig.
More information about the Python-list
mailing list