-5

I am trying to skip parameters while calling a function. Could you please help me how to do this?

Example:

I have to call below function which is having 3 parameters:

send_mail(audit_df, LOG_FILE, Duration)

I have to call above function to skip 1st and 3rd parameters. How can i do this?

Shivam
  • 213
  • 5
  • 14

3 Answers3

3

You can setup default values for the parameters. I don't know what works for you, so I just set them to None.

def send_mail(audit_df=None, log_file=None, duration=None):
    do all the things

when calling

send_mail(log_file="myfile")

For a little light reading see the Function definitions section of the docs.

tdelaney
  • 73,364
  • 6
  • 83
  • 116
0

You can place "None" in place of the parameter.

This is going to make python assume that it is Nothing and will do nothing.

  • 1
    Python will assign `None` to the variables but after that, its up to the code what to do. Its not that its nothing and python will do nothing, its that `None` is assigned and if the code doesn't handle that case, exceptions will ensue. – tdelaney Aug 18 '20 at 05:47
0

This can be done in two ways using

  1. **kwargs
  2. Optional parameters

See the answer below for details

Multiple optional arguments python