title: Evaluating a mathematical expression in a string
body: <pre><code>stringExp = "2^4"
  intVal = int(stringExp)      # Expected value: 16
  </code></pre>
  
  <p>This returns the following error:</p>
  
  <pre><code>Traceback (most recent call last):  
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  ValueError: invalid literal for int()
  with base 10: '2^4'
  </code></pre>
  
  <p>I know that <code>eval</code> can work around this, but isn't there a better and - more importantly - safer method to evaluate a mathematical expression that is being stored in a string?</p>