Python 2.3b1: RuntimeError using rexec

Just just at xs4all.nl
Tue Apr 29 21:53:27 CEST 2003


In article <b8mh4l$2oo0$1 at nntp6.u.washington.edu>,
 "Russell E. Owen" <no at spam.invalid> wrote:

> I stumbled across this when testing some existing code. This code uses 
> rexec to convert a string representation of a dictionary to a dictionary 
> as part of reading in font preferences.
> 
> Any suggestion on how to do that without rexec would also be 
> appreciated. (I was quite disappointed that "dict" didn't do it!)

For this 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...

Just




More information about the Python-list mailing list