-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?

6
  • 4
    Are you writing that function, or is that function provided by someone else? Commented Aug 18, 2020 at 5:40
  • I am writing this function Commented Aug 18, 2020 at 5:42
  • 2
    Then read "Python default arguments". Commented Aug 18, 2020 at 5:43
  • 1
    Change it like this: send_mail( LOG_FILE,audit_df=DEFAULT_VALUE, Duration=DEFAULT_VALUE) and ignore them with DEFAULT_VALUE Commented Aug 18, 2020 at 5:44
  • 1
    If you are writing that function, use keyword arguments with default values. But that's just basics. Commented Aug 18, 2020 at 5:45

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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 Comment

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.
0

This can be done in two ways using

  1. **kwargs
  2. Optional parameters

See the answer below for details

Multiple optional arguments python

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.