Using a dictionary of variable names with eval()
<p>I know eval() is very useful for things like this:</p>

<pre><code>x = 3
y = 2
myformula = "x + y"
print eval(myformula)
&gt;&gt;&gt; 5
</code></pre>

<p>But what if I don't want to hardcode variable names and values but instead used a dictionary? </p>

<pre><code>mydict = {'x':3, 'y':2, 'z':5}
myformula = "x + y + z"
print eval(myformula)
&gt;&gt;&gt; 10
or,
mydict = {'a':100, 'b':10, 'c':1}
myformula = "(a * b) - c"
print eval(myformula)
&gt;&gt;&gt; 999
</code></pre>

<p>I looked up how to assign a variable to a variable but I couldn't apply those other answers to my problem. I still want to keep that notation for myformula string. Any help would be appreciated.</p>

<p>Thanks.</p>

<p>Paul<br>
Chicago, IL</p>
