user73383 user73383 - 1 year ago 71
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
Answer Source

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

def saveValues(file, *data, **kwargs):
    delim = kwargs.pop('delim', '|')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download