parameter passing question

Mathias Waack M.Waack at gmx.de
Tue Sep 21 17:40:36 EDT 2004


Micah wrote:

> Python gurus:

It can't be a guru question just because I know the answer;)

> So, what I'm trying to do is call f(args[0], args[1]).  However, I
> want to
> be able to do it with any length argument list.  Given any function
> f and a list of arguments args, I want to be able to call
> f(args[0], args[1], ..., args[n])

If args is a list: 

>>> def c(f, args):
...     return f(*args)

So you can call for instance: 

        c(max,[1,2,3,4])

Or a function with an arbitrary number of arguments: 

>>> def c(f,*args):
...     return f(*args)

So you can call it as

        c(max,1,2,3,4,5)

Mathias



More information about the Python-list mailing list