Re: Some python comments/questions

Guido.van.Rossum@cwi.nl
Wed, 13 Oct 1993 16:41:30 +0100

> I often get bitten by this. Would it be possible to let eval() set
> some flag or something whereby either the compiler or the runtime code
> would stop accessing local variable the cheap way, but go through the
> dictionary instead?

I walked over to Jack's office to explain why this wasn't a good idea,
and in the ensueing discussion we suddenly came up with the following
solution: make exec a statement instead of a function. The syntax
would be

exec <expression> [in <expression> [, <expression>]]

and the compiler can switch off any optimizations for functions
containing exec statements. There is a precedent for this: the same
happens when the compiler sees "from <module> import *", because it
can't tell what local variables the star will introduce.

The change will break some existing Python code: statements calling
exec() with an explicit global and/or local dictionary. The majority
of exec() function calls will still work since the extra parentheses
are harmless.

How about it?

--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>