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. this page was rendered by a django application in 0.02s 2008-08-30 00:06:10.948953. hosted by webfaction.