Working around a lack of 'goto' in python

Terry Reedy tjreedy at udel.edu
Wed Mar 10 11:59:43 EST 2004


"Isaac To" <kkto at csis.hku.hk> wrote in message
news:7ismggofrt.fsf at enark.csis.hku.hk...
> >>>>> "Jeff" == Jeff Epler <jepler at unpythonic.net> writes:
>
>     Jeff> Are you certain that calling a function allocates a dictionary?
A
>     Jeff> function's locals are stored as indices in a C array unless a
>     Jeff> function uses bare exec.  I'm not sure what a dictionary is
needed
>     Jeff> for.
>
> You mean a function which calls the locals() function is byte-compiled
> differently from a function that won't call locals()?

Of course.  One has a call to the locals() function and the other does not.
Note that writing to the dict returned by locals() is *NOT* guaranteed to
affect the local namespace that the dict is a copy of.  Specifics can be
version dependent, as revealed by disassembly with the dis module.

Terry J. Reedy







More information about the Python-list mailing list