problem with accessing methods?
Remco Gerlich
scarblac-spamtrap at pino.selwerd.nl
Tue Jun 27 10:56:28 EDT 2000
Mike 'Cat' Perkonigg wrote in comp.lang.python:
> How can I access a method with variable amount of parameters?
> I have sort of an object management system which routes method invocations
> from outside to the objects, but the management system don't know anything
> about the methods.
> In C I would use a pointer to a struct, but this is Python :-)
You use apply(). apply(f, args) calls the function f with the arguments
given in the tuple 'args'.
To make a function that takes multiple arguments, use
def my_apply(func, *args):
return apply(func, args)
(args is a tuple containing the values passed in).
To handle keyword arguments as well, use
def my_apply(func, *args, **kw_args):
return apply(func, args, kw_args)
In this case, kw_args is a dictionary with keyword: value pairs. Just play
around in the interpreter a bit, it's quite simple but looks complicated the
first time you see it...
--
Remco Gerlich, scarblac at pino.selwerd.nl
This is no way to be
Man ought to be free -- Ted Bundy
That man should be me
More information about the Python-list
mailing list