Passing a variable number of arguments to a wrapped function.

Bengt Richter bokr at oz.net
Fri Aug 5 14:02:44 EDT 2005


On 5 Aug 2005 08:34:32 -0700, stephen at theboulets.net wrote:

>Is there a better way of doing this so that I don't have to go through
>every permutation of possible arguments (the example here from the
>matplotlib 'plot' function):
>
>def makeplot(self, xvalues, yvalues, linecolor='', linewidth=''):
>    if linecolor and linewidth:
>        plot(xvalues, yvalues, linecolor, linewidth=linewidth)
>    elif linecolor:
>        plot(xvalues, yvalues, linecolor)
>    elif linewidth:
>        plot(xvalues, yvalues, linewidth=linewidth)
>    else:
>        plot(xvalues, yvalues)
>

It seems like you are not changing the order or values of arguments,
so I'm wondering if this would work for you:

 def makeplot(self, *args, **kwargs):
     plot(*args, **kwargs)

and if not, why not.

Regards,
Bengt Richter



More information about the Python-list mailing list