user73383 user73383 - 11 months ago 43
Python Question

Python Using Keyword and variable number of arguments in same function

I am wondering if there is a way to do something like this in python 2.7.12

def saveValues(file,*data,delim="|"):
for d in data:
buf+=str(d) + delim

So that I have the option to pass delim, or take the default.

wim wim

It's possible in python3. The python2 workaround is usually this:

def saveValues(file, *data, **kwargs):
    delim = kwargs.pop('delim', '|')