This is an old copy of the Python FAQ. The information here may be outdated.

How can I pass optional or keyword parameters from one function to another?

Collect the arguments using the * and ** specifiers in the function’s parameter list; this gives you the positional arguments as a tuple and the keyword arguments as a dictionary. You can then pass these arguments when calling another function by using * and **:

def f(x, *args, **kwargs):
        ...
        kwargs['width']='14.3c'
        ...
        g(x, *args, **kwargs)

If you have to support Python versions older than 2.0, use apply:

def f(x, *args, **kwargs):
        ...
        kwargs['width']='14.3c'
        ...
        apply(g, (x,) + args, kwargs)

CATEGORY: programming

 

A Django site. rendered by a django application. hosted by webfaction.