Accessing function in a module by name

John Machin sjmachin at lexicon.net
Wed Jun 6 18:18:38 EDT 2007


On Jun 7, 8:13 am, Tobiah <t... at tobiah.org> wrote:
> Is there a way to call function in an imported
> module having only the name?
>
> func_name = 'doit'
>
> real_func = foo.some_magic(func_name)

Presuming 'foo' is the name of the module:

real_func = getattr(foo, func_name)

>
> #Now call it
> real_func(args)
>




More information about the Python-list mailing list