Accessing function in a module by name

John Machin sjmachin at lexicon.net
Thu Jun 7 00:18:38 CEST 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