Modul gotchas:)

Sylvain Thenault syt at gemini.logilab.fr
Wed Jan 2 07:55:24 EST 2002


On Wed, 02 Jan 2002 13:13:44 -0800, Giorgi Lekishvili <gleki at gol.ge> wrote:
>Hi all!
>
>happy new year, first of all!!!
>
>My question is simple, yet I missed the right answer, although have lots
>of books on Python:(
>
>Suppose, one has a module, which defines some set of functions.
>
>The question:
>
>How can one get the names of all these functions as list entries?
>
>E.g.,
>
>all_func=[]
>
>import myModule
>
>all_func=myModule.functions()
>
>of course, this will not work.
>
>What is to be done? Some special functions are to be written or, is
>there a built-in tool?

you can use the built-in "dir" function to do things like that. 
The following code filters functions from the "dir" output:

import myModule
for f in dir(myModule):
    if callable(getattr(myModule, d)):
        print d

cheers 

-- 
Sylvain Thenault

  LOGILAB           http://www.logilab.org




More information about the Python-list mailing list