[Python-3000] Ripping out exec
Guido van Rossum
guido at python.org
Fri Sep 1 23:57:18 CEST 2006
On 9/1/06, Georg Brandl <g.brandl at gmx.net> wrote:
> Guido van Rossum wrote:
> > I would just rip it out.
>
> It turns out that it's not so easy. The exec statement currently can
> modify the locals, which means that
>
> def f():
> exec "a=1"
> print a
>
> succeeds. To make that possible, the compiler flags scopes containing
> exec statements as unoptimized and does not assume unbound names to
> be global.
>
> With exec being a function, currently the above function won't work
> because "a" is assumed to be global.
>
> I can see only two resolutions:
>
> * change exec() semantics so that it cannot modify the locals
> * do not make exec a function
Make it so it can't modify the locals. execfile() has the same limitation.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000
mailing list