title: NameError: name 'PI' is not defined?
body: <p>I am trying to create a Formula() function that takes as argument an algebraic formula (that uses Python syntax) and returns a new class. The constructor of that class takes as argument a string of comma-separated variable=value pairs. Finally, the class has a calc() method that evaluates its formula using the given variable values and prints the result.<br>
  Problem is here it will work: </p>
  
  <pre><code>triangle_hypotenuse = Formula('(a*a + b*b)**0.5')
  print(triangle_hypotenuse('a=3, b=4') .calc())
  </code></pre>
  
  <p>but when i try:</p>
  
  <pre><code>cylinder_volume = Formula('PI * r**2 * h')
  cylinder_volume('r= 1, h=2') .calc()
  </code></pre>
  
  <p>I get the error <em>NameError: name 'PI' is not defined</em> how can i make it reference the pi from the math module?</p>
  
  <p>Here is my full code</p>
  
  <pre><code>import math
  from math import pi,cos,sin,tan,atan
  
  # eval('a + sin(p/2)', bindings)    # 'sin' not defined
  
  def Formula(expression):
      class F:
  
          def __init__(self,kwargs):
              s = kwargs.replace(',','')
              l=((s.replace('=',' ').split()))
  
              it = iter(l)
  
              self.res_dct = dict(zip(it,it))
              self.res_dct=  {k:float(v) for k, v in self.res_dct.items()}
  
              class Foo:
                  def setAllWithKwArgs(self, **kwargs):
                      for key, value in kwargs.items():
                          setattr(self, key, value)
  
          def calc(self):
  
              return eval(expression,self.res_dct)
  
      return F
  
  triangle_hypotenuse = Formula('(a*a + b*b)**0.5')
  print(triangle_hypotenuse('a=3, b=4') .calc())
  
  cylinder_volume = Formula('PI * r**2 * h')
  cylinder_volume('r= 1, h=2') .calc()
  </code></pre>