Getting definition list
Russell E. Owen
no at spam.invalid
Mon Mar 8 18:20:31 EST 2004
In article <c2cjf3$8bf$1 at news1.tilbu1.nb.home.nl>,
"vincent wehren" <vincent at visualtrans.de> wrote:
>"Bluexcell" <bluexcell at aol.com> schrieb im Newsbeitrag
>news:20040306071202.18241.00000981 at mb-m06.aol.com...
>| ok so i use import to import a py file into my script.
>|
>| is there a way to list all the defined function labels that exist in the
>| imported file?
>|
>| ie if i import a file called test and test has defined functions called
>| myfunction1 my function2 myfunction3 etc but i dont know them, is
>there a
>| method to list all the function labels in test and print them as a
>listing
>|
>| test.mfunction1
>| test.myfunction2
>| test.myfunction3
>|
>| etc.
>
>Roughly (untested) something like the following should get you started:
>
>import some_module
>import types
>d = some_module.__dict__
>for k in d:
> obj = d[k]
> if type(obj) == types.FunctionType:
> print "some_module.%s" % k
Or if you care about callable objects (i.e. anything that acts like
functions) then replace the type(obj) test with "if callable(obj):".
-- Russell
More information about the Python-list
mailing list