[Python-3000] Ripping out exec

Guido van Rossum guido at python.org
Sat Sep 2 04:26:46 CEST 2006


On 9/1/06, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Guido van Rossum wrote:
> > I would just rip it out.
>
> I don't understand this business about ripping out
> exec. I thought that exec had to be a statement so
> the compiler can tell whether to use fast locals.
> Do you have a different way of handling that in mind
> for Py3k?

Yes. If we implement the module-level analysis it should be easy
enough to track whether 'exec' refers to the built-in function. (We're
already planning to add some kind of prohibition against outside
modules poking new globals into a module that shadow built-ins.)

But I also see no bones in requiring the use of a dict arg if you want
to observe the side effects of the exec'ed code. So instead of

  def f(s):
    exec s
    print a # presumably s must contain an assignment to a

you'd have to write

  def f(s):
    ns = {}
    exec(s, ns)
    print ns['a']

This makes it a lot clearer what happens IMO.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list