Assume you have a function like that:
def example(var1=None,var2=None,var3=None,*multi_values):
print (var1,var2,var3,*multi_values)
Can you get around calling all the optional parameters and just adding stuff to the last one?
Example:
>>> multi=range(3)
>>> example(???)
(None,"hi",None,(1,2,3))
I don’t want to do this:
>>> multi=range(3)
>>> example(None,None,None,*multi) #bad -> this doesn't use the default values
One option is to change you prototype to take an iterable as
multi_valuesargument, instead of accepting an arbitrary number of parameters:Then you can call the function as
Another option is to accept
var1throughvar3only as keywords arguments:In Python 3.x, this is supported by adding
var1throughvar3after the*multi_valuesargument:This does basically the same as the previous example, with the additional advantage of better introspection.