Using exec with local dictionary from another routine

Terry Reedy tjreedy at udel.edu
Fri Aug 9 12:51:38 EDT 2002


"Robert McLay" <mclay at cfdlab.ae.utexas.edu> wrote in message
news:3D53DD26.5E551960 at cfdlab.ae.utexas.edu...
> So when in the "delay" routine it knows the id(f) is the same as in
the  main function
> but when the change the value of "f" in the exec statement it
creates a new "f" and
> assigns it to 3.  What am I missing here?

That local really means local (in the case of functions).

The local namespace of a function is *not* a dictionary.  locals() is
a *copy* in dictionary form and is readonly as far as the local
namespace is concerned (ie, modifications of the copy do not propagate
back).   The only way you *might* be able to do what you want is to
pass a reference to the function itself and then access its code
object (see new module for list of members), but the local var array
would  still be unwritable from Python if it is a C rather than Python
array.

Terry J. Reedy






More information about the Python-list mailing list