Converting a string to a tuple

Fredrik Lundh fredrik at pythonware.com
Tue Apr 13 03:26:50 EDT 1999


Charles G Waldman wrote:
> If you're concerned about safety (the "eval" could be evaluating any
> Python code, possibly a hazard if the string is coming from user
> input) then you don't want to use eval at all.

try:

    result = eval(string, {"__builtins__": {}})

or:

    import rexec
    r = rexec.RExec()
    result = r.r_eval(string)

</F>





More information about the Python-list mailing list