calling a function indirectly
Michal Wallace
sabren at manifestation.com
Wed Feb 20 01:13:19 EST 2002
On Tue, 19 Feb 2002, Rajarshi Guha wrote:
> Hi,
> is it possible to have a variable contain a function name, and use the
> variable to call the function?
> An example:
>
> def func:
> some code
>
> funcvar = 'func'
>
> Now use funcvar (somehow!) to call func
I also think the easiest thing to use is funcvar = func,
but if for some reason it has to be a string, you can
use exec, or:
locals()[funcvar]("whatever")
Cheers,
- Michal http://www.sabren.net/ sabren at manifestation.com
------------------------------------------------------------
Give your ideas the perfect home: http://www.cornerhost.com/
cvs - weblogs - php - linux shell - perl/python/cgi - java
------------------------------------------------------------
More information about the Python-list
mailing list