title: python: dispatch method with string input
body: <p>I need to write a method that takes in 3 arguments:</p>
  
  <ol>
  <li>a <code>string</code> with the name of a function</li>
  <li>an ordered <code>list</code> of arguments to that function.  This includes arguments with default values and <code>*varargs</code>, but does not include <code>**kwargs</code></li>
  <li>a <code>dict</code> representing any additional keyword arguments, or <code>None</code> if there are none</li>
  </ol>
  
  <p>And I need to use this input to retrieve a function and call it.  For example:</p>
  
  <pre><code>def dispatch(name, args, kwargs=None):
      do_magic_here(name, args, kwargs)
  
  def meth1():
      print "meth1"
  
  def meth2(a, b):
      print "meth2: %s %s" % (a, b)
  
  def meth3(a, **kwargs):
      print "meth3: " + a
      for k,v in kwargs.iteritems():
          print "%s: %s" % (k,v)
  </code></pre>
  
  <p>And I need to be able to call things like this:</p>
  
  <pre><code>&gt;&gt;&gt; dispatch("meth1", [])
  meth1
  &gt;&gt;&gt; dispatch("meth2", [1, 3])
  meth2: 1 3
  &gt;&gt;&gt; dispatch("meth3", [1], {"hello":2, "there":3})
  meth3: 1
  hello: 2
  there: 3
  </code></pre>
  
  <p>I could do this:</p>
  
  <pre><code>def do_magic_here(name, args, kwargs=None):
      if name=="meth1":
          meth1()
      if name=="meth2":
          meth2(args[0], args[1])
      if name=="meth3":
          meth3(args[0], **kwargs)
  </code></pre>
  
  <p>But I'm trying to dispatch like 40 methods, and that number may expand, so I'm hoping there's a more programmatic way to do it.   I'm looking at something with <code>getattr</code>, but I can't quite figure it out.</p>