function arguments

Larry Bates lbates at swamisoft.com
Wed Sep 15 23:54:37 CEST 2004


Paul has explanation (see his response), but I
wanted to expand a little.

def foo(*args, **kwargs):
    for arg in args:
        print arg
    for key, value in kwargs.items():
        print key, value
    return

>>> foo('a','b',x=1,y=2)
a
b
y 2
x 1

or

def foo(list_of_args, **kwargs):
    #
    # Now call function with args as individual arguments
    # and keyword arguments as individual keyword
    # arguments also.
    #
    call_other_function(*list_of_args, **kwargs)
    return

Hope this helps,
Larry Bates


"Joe Laughlin" <Joseph.V.Laughlin at boeing.com> wrote in message 
news:I43MHJ.66G at news.boeing.com...
>I want to do something like the following
>
> def foo(list_of_args):
>    call_other_function(arg1, arg2, arg3)
>    # Where arg1 == "x", arg2 == "y", etc.
>    # Should work with any list size
>
> foo(["x", "y", "z"])
>
> Make sense?  Need clarification?  In summary, I want to pass a list of
> arguments to a function.  The function needs to pass each argument in the
> list to a different function.
>
> Thanks,
> Joe
>
> 





More information about the Python-list mailing list