Python 2.3b1: RuntimeError using rexec

Russell E. Owen no at spam.invalid
Tue Apr 29 17:17:55 EDT 2003


Thank you very much. That sounds much better than just a bare "eval".

I could probably also get pickle to do the job, also. A brief inspection 
suggests it puts repr(dict) in some simple boilerplate (at least for 
trivial dicts such as mine -- consisting only of strings and numbers). 
But I'd sure have to learn more before I'd believe that. Your safe eval 
seems much safer from that angle.

-- Russell

In article <just-53D0EC.21532729042003 at news1.news.xs4all.nl>,
 Just <just at xs4all.nl> wrote:

>For ...(converting a string repr of  a simple dict back to a dict)... I often use
>
>def safeEval(data):
>   """A safe replacement for eval."""
>   return eval(data, {"__builtins__": {}}, {})
>
>Exactly _how_ safe it is I don't know, but it's safe enough for my 
>purposes...




More information about the Python-list mailing list