Problems passing a function and its args around.

Hammond, Mark (MHammond@jm.cmutual.com.au)
Tue, 14 Mar 95 22:31:00 PST

Hi all,
I need to set up a function that takes 2 parameters - a function
object, and a tuple of parameters for the function. I would then like the
passed function to be called, with the parameters.

To explain:
>>> def test(a,b,c):
... print "a=%s, b=%s, c=%s" % (a,b,c)
...
>>> def CallPasser( fn, args ):
... print "Args are ", args
... fn (args)
...
>>> CallPasser(test, ('a','b','ccc'))
What I am hoping to get out of the above statement is for the function
test() to be called, as if "test('a','b','ccc')" had been typed at the
prompt.

I have tried "def CallPasser( fn, * args ):", and a couple of other
variations, but always get a TypeError: arg count mismatch.

[Actually, the problem is in C code. Currently, 'C' code calls test()
directly, which works fine. Now, I am trying to make the 'C' code call
CallPasser() instead, which is Python code, which calls the _real_ target of
the callback. But I think the above example is the same as my problem!]

Thanks,

Mark.