gettin a list of functions?

Gerson Kurz gerson.kurz at t-online.de
Mon Dec 9 10:46:12 EST 2002


On 9 Dec 2002 07:35:22 -0800, hu.peress at mail.mcgill.ca (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.

AFAIK you should check for stuff that is callable(). Basically, use
callable(getattr(module,objectname)) to decide whether
module.objectname is a function-like thingy or not. 

for each symbol exported by some module:
	if that symbol is callable, its a function

In lambdaesque python:

getfuncs = lambda m:filter(None,map(lambda
x:["",x][callable(getattr(m,x))],dir(m)))

(Should be one line, but is probably too long).




More information about the Python-list mailing list