Modul gotchas:)

Sylvain Thenault syt at
Wed Jan 2 13:55:24 CET 2002

On Wed, 02 Jan 2002 13:13:44 -0800, Giorgi Lekishvili <gleki at> 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?
>import myModule
>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


Sylvain Thenault


More information about the Python-list mailing list