I am wondering if there is a way to do something like this in python 2.7.12
def saveValues(file,*data,delim="|"):
buf=""
for d in data:
buf+=str(d) + delim
open(file,"w").write(buf[:-1])
So that I have the option to pass delim, or take the default.
It's possible in Python 3.0+, after implementation of PEP 3102 -- Keyword-Only Arguments. The syntax would be exactly how you've shown it, in fact.
The usual workaround for Python 2 is this:
def saveValues(file, *data, **kwargs):
delim = kwargs.pop('delim', '|')
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With