eval modifies passed dict

Arnaud Delobelle arnodel at googlemail.com
Mon Apr 14 11:55:35 EDT 2008


On Apr 14, 4:23 pm, Janto Dreijer <jan... at gmail.com> wrote:
> It seems eval is modifying the passed in locals/globals. This is
> behaviour I did not expect and is really messing up my web.py app.

Reading the documentation would be a good start:

From http://docs.python.org/lib/built-in-funcs.html:

eval(	expression[, globals[, locals]])
The arguments are a string and optional globals and locals. If
provided, globals must be a dictionary. If provided, locals can be any
mapping object. Changed in version 2.4: formerly locals was required
to be a dictionary.
The expression argument is parsed and evaluated as a Python expression
(technically speaking, a condition list) using the globals and locals
dictionaries as global and local name space. If the globals dictionary
is present and lacks '__builtins__', the current globals are copied
into globals before expression is parsed.

--
Arnaud




More information about the Python-list mailing list