[Tutor] "Dispatching" functions with args

Luke Jordan luke.jordan at gmail.com
Thu Apr 14 01:53:40 CEST 2005


Hi!

I am using a suggestion from this list to handle calling different
functions conditionallly based on user input. What I'm trying to do is
have functions that are 'configurable' in the sense that a choice from
the user affects the way it performs.

This works:

    def aFunc():
        print "aFunc"

    def dispatch(func):
        while func is not None:
            func = func()

But this does not:

    def aFunc(configArg):
        print "aFunc with argument"
        print configArg

    def anotherFunc(configArg):
        print "anotherFunc with argument"
        print configArg  
        return aFunc,1

    def dispatch(func,configArg):
        while func is not None and configArg is not None:
            func = func(configArg)

    dispatch(anotherFunc,1)

I get TypeErrored:

Traceback (most recent call last):
  File "E:/gibberish/current work/test2.py", line 14, in ?
    dispatch(aFunc,1)
  File "E:/gibberish/current work/test2.py", line 12, in dispatch
    func = func(funcArg)
TypeError: 'tuple' object is not callable

I understand *that* a tuple is not callable, but not why this is
happening here, or how to solve this problem.

Thanks in advance for your input!

Luke

-- 
"Scalpel....blood bucket....priest....next patient."


More information about the Tutor mailing list