passing a variable argument list to a function

Scott smbaker at gmail.com
Wed Aug 13 02:02:51 CEST 2008


I'm trying to write a function that accepts a variable number of
arguments and passes those arguments to another function. Here is an
example:

def foo(*args):
    print "I'm going to call bar with the arguments", args
    bar(args)

This doesn't do quite what I want. For example, if I call foo(1,2,3,4)
then it calls bar((1,2,3,4)). It passes a tuple rather than expanding
the argument list back out.

I suspect there's a simple bit of syntax that I'm missing -- can
anyone give me a hand?

Thanks
Scott



More information about the Python-list mailing list