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

Tim Peters tim_one at email.msn.com
Mon Aug 23 01:58:23 EDT 1999


[Thomas Wouters]
> Out of curiosity, is the compiler smart enough to see that
> exec statements like
>
> exec "a = 1 * 10" in {}
>
> or
>
> exec "foo = bar * zed" in {'bar': 5, 'zed', 'z'}
> ...

No.  It would first have to parse the exec'ed string at compile-time, but
that's delayed to run-time, too late to help the local/global decisions made at
compile-time.  In real execs, one or more of the arguments are unknown at
compile-time anyway (nobody would write the above in a real program, but if
you're the exception feel free to submit a tedious patch to look for stuff like
that <wink>).

most-optimizations-aren't-ly y'rs  - tim






More information about the Python-list mailing list