calling a function indirectly

Grant Edwards grante at
Wed Feb 20 05:30:15 CET 2002

In article <a4v7s6$13tk at>, 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

How about this:

    def func():
        print "hello"
    x = func


It doesn't use the name of the function, but if you really want
to do it that way you can do this:

    def func():
        print "hello"
    x = "func"


Grant Edwards                   grante             Yow!  I want a VEGETARIAN
                                  at               BURRITO to go... with
                                 EXTRA MSG!!

More information about the Python-list mailing list