Modify the local scope inside a function

Sandra-24 sandravandale at yahoo.com
Sat Feb 25 18:53:08 EST 2006


Is there a way in python to add the items of a dictionary to the local
function scope? i.e. var_foo = dict['var_foo']. I don't know how many
items are in this dictionary, or what they are until runtime.

exec statements are difficult for debuggers to deal with, so as a
workaround I built my code into a function and saved it in a .py file.
The I load the .py file as a module and call the function instead. This
works great, and it has the added advantage of precompiled versions of
the code being saved as .pyc and .pyo files. (faster repeated
execution)

The only trouble was I execed inside a specially created scope
dictionary containing various variables and functions that the code
requires. I can't seem to figure out how to get this same effect inside
the function. Right now I'm passing the dict as an argument to the
function, but I can't modify locals() so it doesn't help me.

Thanks,
-Sandra




More information about the Python-list mailing list