title: using exec and compile in python
body: <p>I want to have a dictionary where the value is a statement.  I don't need to build the statement dynamically.  The names appearing in the statement are in the local scope. A simple example appears below.  It seems like 'exec' is the thing to use, but this appears to be frowned upon, and is probably slow.  This code will be used in a stochastic modeler, and will be run gazillions of times.  Could you suggest to me how to best accomplish this idea (maybe by precompiling?).  Could it be I already have this right?</p>
  
  <p>Cheers!</p>
  
  <p>Jeff</p>
  
  <pre><code>d={'plusone':'x+=1','minusone':'x-=1'}
  x=2
  exec(d['plusone'])
  print x  ::: output '3'
  exec(d['minusone'])
  print x  ::: output '2'
  </code></pre>