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

Thomas Wouters thomas at xs4all.nl
Mon Aug 23 03:52:17 EDT 1999

On Mon, Aug 23, 1999 at 01:58:23AM -0400, Tim Peters wrote:

> > Out of curiosity, is the compiler smart enough to see that
> > exec statements like
> > exec "a = 1 * 10" in {}

> 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>).

Heh, like i said, it was curiosity. I can imagine code doing the above to
provide simple syntax checking before writing the exec'd code to a .py file
for use later. However, I dont plan on writing anything that does that
without using 'exec' in other places, and cares about speed. I'll use the
extra runtime to make loving python-remarks to the perl-loving colleague who
sits across from me ;-)

Nevertheless, compiler and language internals fascinate me. As do computer
internals in general. Which reminds me... I hardly see any
'development-traffic' on this list, other than some sideways references to a
CVS tree... Is there a secret society or do you just have meetings in
guido's favorite pub ?

Noisily-and-nosey-y'rs, Thomas

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