title: Conditional passing of arguments to methods in python
body: <p>I have many possible arguments from argparse that I want to pass to a function. If the variable hasn't been set, I want the method to use its default variable. However, handling which arguments have been set and which haven't is tedious:</p>
  
  <pre><code>import argparse
  def my_func(a = 1, b = 2):
    return a+b
  
  if __name__ == "__main__":
      parser = argparse.ArgumentParser(description='Get the numeric values.')
      parser.add_argument('-a', type=int)
      parser.add_argument('-b', type=int)
      args = parser.parse_args()
  
      if not args.a is None and not args.b is None:
          result = my_func(a = args.a, b = args.b)
      elif not args.a is None and args.b is None:
          result = my_func(a = args.a)
      elif not args.b is None and args.a is None:
          result = my_func(b = args.b)
      else:
          result = my_func()
  </code></pre>
  
  <p>It seems like I should be able to do something like this:</p>
  
  <pre><code>result = my_func(a = args.a if not args.a is None, b = args.b if not args.b is None)
  </code></pre>
  
  <p>But this gives a syntax error on the comma. </p>
  
  <p>I could set default values in the argparser, but I want to use the defaults set in the method definition.</p>