[Python-3000] Ripping out exec

Georg Brandl g.brandl at gmx.net
Fri Sep 1 23:28:15 CEST 2006

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


More information about the Python-3000 mailing list