title: How to update local variables in function with a dictionary?
body: <p>A problem meeted in rewriting a python program.</p>
  
  <p>I move some previous global variables into a dictionay, so I have to rewrite the functions which have used those variables.</p>
  
  <p>For example,</p>
  
  <pre><code>#old one
  a, b = 1, 2    
  def func(c):
      print a+b+c
  
  #new one
  d = dict(a=1,b=2)
  def func(c,d):
      a = d['a']
      b = d['b']
      print a+b+c
  </code></pre>
  
  <p>As the <em>dictionary d</em> is large, so I'm seeking a something like this </p>
  
  <pre><code>d = dict(a=1,b=2)
  def func(c,d):
      locals().update(d)
      print a+b+c
  </code></pre>
  
  <p>I have tried  <code>__dict__.update(d)</code>, however <code>__dict__</code> can't be accessed directly.</p>
  
  <p>Or <code>for key,value in d.items():
      setattr(obj,key,value)</code>
  is possible? If yes, how to set the obj to the function itself?</p>