Popular recipes by Michael Spencer http://code.activestate.com/recipes/users/2106310/2006-03-26T18:13:43-08:00ActiveState Code Recipes"Safe" Eval (Python)
2006-03-26T18:13:43-08:00Michael Spencerhttp://code.activestate.com/recipes/users/2106310/http://code.activestate.com/recipes/364469-safe-eval/
<p style="color: grey">
Python
recipe 364469
by <a href="/recipes/users/2106310/">Michael Spencer</a>
(<a href="/recipes/tags/text/">text</a>).
Revision 2.
</p>
<p>Evaluate constant expressions, including list, dict and tuple using the abstract syntax tree created by compiler.parse. Since compiler does the work, handling arbitratily nested structures is transparent, and the implemenation is very straightforward.</p>