eval(source, {'builtins': {}}) archived as Faq

Paul Rubin http
Thu Sep 28 19:32:15 EDT 2006


p.lavarre at ieee.org writes:
> Q: How can I tell Python to calculate what quoted strings and numbers
> mean, without also accidentally accepting OS commands as input?
> 
> A: eval(source, {'builtins': {}})

That is dangerous.  Consider source = "9**9**9".  There's a better
recipe on ASPN:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469



More information about the Python-list mailing list