parameter passing question
Robert Brewer
fumanchu at amor.org
Mon Sep 20 18:16:44 EDT 2004
Micah wrote:
> Basically, I want to be able to call a function on a list of arguments
> without knowing the syntax of the function. I guess a code
> example would be
> best:
>
> -------
> def foo(arg1, arg2):
> # Do something with arg1 and arg2
>
> def main():
> f = foo
> args = ["hello", "world"]
> # Want to call foo("hello", "world") using variable f and
> list args
> --------
>
> 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])
Use the variable-arg techniques described in:
http://docs.python.org/ref/function.html
def foo(*args):
# Do something with arg[0], arg[1], ...
def main():
f = foo
args = ["hello", "world"]
f(*args)
HTH,
Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org
More information about the Python-list
mailing list