Suppose I had a function that takes optional keyword arguments (**kwargs). I want to do three different things depending if (i) this argument was passed along with a specific value, (ii) it was passed without the specific value, (iii) it wasn't passed.
What I have so far. Example:
def myfunc(**kwargs):
... do stuff
myfunc(print_job=True)
# output:
# Incoming print job. myfunc was called.
myfunc(print_job=False)
# output:
# No incoming print jobs. myfunc was called.
myfunc()
# output:
# myfunc was called.
What's the proper way to deal with kwargs in this case? Is it literally, checking for the specific value using two if-statements, like:
def myfunc(**kwargs):
if 'print_job' in kwargs:
if kwargs['print_job'] is True:
#... do stuff
else:
# ... do stuff
else:
# ... do stuff
or is there other more Pythonic way?