title: argparse - how pass to a method with kwargs or argv
body: <p>I've been looking for a way to use <code>**kwargs</code> or <code>*argv</code> with <code>argparse</code>. I will from hard code to a dynamic way.</p>
  
  <p>Here is my hard code and a example how I will use it.</p>
  
  <pre><code>def get_parser():
      parser = argparse.ArgumentParser()
      parser.add_argument("-r",
                          "--range",
                          dest="r",
                          nargs=8,
                          help="AddRange Parameters")
      parser.add_argument("-p",
                          "--parameters",
                          dest="p",
                          nargs=8,
                          help="SetDefaults as Parameters")
      parser.add_argument("-r",
                      "--range",
                      dest="r",
                      nargs=8,
                      help="AddRange Parameters")
      return parser
  
  """Create a Template for a Job"""
  def create_Template(temp3_,temp_tournsize,temp_popsize,temp0_,temp1_,temp_ngen,temp_run,tmpverb):
      #single GA job
      logging.basicConfig(level=logging.DEBUG)
      template = job.JobTemplate(runGASimple)
      print tmpverb
      template.setDefaults(temp3=temp3_, tournsize=temp_tournsize, popSize=temp_popsize, temp0=temp0_, temp1=temp1_, ngen=temp_ngen, number_of_runs=temp_run, verbose=tmpverb)
      return template
  
  """Run a simple Job"""
  def ajob_run(template):
      ajob = job.Job(template)
      ajob.run()
      pass
  
      """change Default params with AddRange"""
  def add_Range(var_temp0,var_start,var_end,var_stepSize,var_temp1,var_start2,var_end2,var_stepSize2,tmp_template):
      jobCreator = job.JobCreator()
      #jobCreator.addRange('temp0', start=0.0, end=1.0, stepSize=0.1)
      jobCreator.addRange(var_temp0, start= var_start, end=var_end, stepSize=var_stepSize)
      #jobCreator.addRange('temp1', start=0.0, end=1.0, stepSize=0.1)
      jobCreator.addRange(var_temp1, start=var_start2, end=var_end2, stepSize=var_stepSize2)
      # all other params will take defaults
      jobs = jobCreator.generateJobs(tmp_template)
  
      return jobs
  
  """Create a Batchjob from Jobs"""
  def batch_Job(tmp_jobs):
      batchJob = job.BatchJob(tmp_jobs, 5)
  
      return batchJob
  
  
  if (__name__ == "__main__"):
  
      args = get_parser().parse_args()
      if (args.p and args.r):
          print 'AddRange with Parameters Input Start:'
          temp = create_Template(float(args.p[0]),int(args.p[1]),int(args.p[2]),float(args.p[3]),float(args.p[4]),int(args.p[5]),int(args.p[6]),ast.literal_eval(args.p[7]))
          tmpjobs = add_Range(args.r[0],float(args.r[1]),float(args.r[2]),float(args.r[3]),args.r[4],float(args.r[5]),float(args.r[6]),float(args.r[7]),temp)
          results = batch_Job(tmpjobs)
  
  
          print 'AddRange with Parameters Input Ende.'
      elif (args.p):
              print 'Parameters Input Start:'
          ajob_run(create_Template(
          float(args.p[0]),
          int(args.p[1]),
          int(args.p[2]),
          float(args.p[3]),
          float(args.p[4]),
          int(args.p[5]),
          int(args.p[6]),
          ast.literal_eval(args.p[7])))
          print 'Parameters Input Ende.'
  </code></pre>
  
  <p></p>
  
  <pre><code>CLI.py -p 0.8 20 20 0.5 0.5 20 1 False
  </code></pre>
  
  <p>Then came a long output with results from a framework.</p>
  
  <p>My method expected this. The variable names can be change in the future.</p>
  
  <pre><code>template.setDefaults(mux=0.8, tournsize=20, rangeSize=20, temp0=0.5, temp1=0.5, ngen=20, number_of_runs=1, verbose=False)
  
  jobCreator.addRange('temp0', start=0.0, end=1.0, tournStep=0.1)
  
  jobCreator.addRange('temp1', start=0.0, end=1.0, turns=4)
  </code></pre>
  
  <p>An will change it like this:</p>
  
  <pre><code>setDefaults(**kwargs)
  
  addRange(paraName,**kwargs)
  </code></pre>
  
  <p>I expect this:</p>
  
  <pre><code>CLI.py -p temp0=1 temp1=0.4 ....temp6=8 ... -r temp0 start=0 end=1 tournStep=0.1
  or
  CLI.py -p hn0=1 bn1=0.4 ....tp6=8 ... -r temp1 start=0 end=1 turns=4
  </code></pre>
  
  <p>then convert variablenames with the input to:</p>
  
  <pre><code>setDefaults()
  </code></pre>
  
  <p>and  </p>
  
  <pre><code>addRange()
  </code></pre>
  
  <p>But I need the <code>argparse</code>, because i will build a command line interface.</p>
  
  <p>I have forgot some details about a other method:                                  </p>
  
  <pre><code>    """change Default params with AddSpecific"""
  def add_Specific(tmp_template,paraName,*params):
      jobCreator = job.JobCreator()
      #jobCreator.addSpecific('temp0', 0.1,0.2,0.3,0.4,....,0.7,...)
      jobCreator.addRange(paraName, params)
      # all other params will take defaults
      jobs = jobCreator.generateJobs(tmp_template)
      return jobs
  </code></pre>
  
  <p>Is that the correct way?</p>