"def" vs "sub" (was RE: More random python observations from a perl programmer)

Thomas Wouters thomas at xs4all.nl
Sun Aug 22 21:01:43 CEST 1999

On Fri, Aug 20, 1999 at 05:39:30AM -0400, Tim Peters wrote:

[Tim about Python's compiler & interpreter]
> It's too busy desperately scrounging for excuses to kill your program with a
> bogus SyntaxError to do anything useful <wink>.  About the only compile-time
> optimization is that function locals (in the absence of "exec" and "import
> *" statements) are mapped to consecutive indices into a contiguous runtime
> vector.
> "exec" and "import *" can alter the *set* of local names, so their presence
> inhibits that optimization.  That's why "exec" is a stmt rather than a


Out of curiosity, is the compiler smart enough to see that exec statements

exec "a = 1 * 10" in {}


exec "foo = bar * zed" in {'bar': 5, 'zed', 'z'}

are not able to modify any namespace ? I can understand that something like

exec "foo = bar * zed" in myenv

is too indirect for the compiler to worry about, but the upper two examples
do not use any type of object that isn't 100% certain at compile time... Or
is it possible to redefine builtins like ints, dicts and strings ? ;) (Or
isn't the compiler aware of this ?)

Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!

More information about the Python-list mailing list