Modify the local scope inside a function

Jason Mobarak jason.mobarak at gmail.com
Sun Feb 26 01:16:31 EST 2006


Sandra-24 wrote:
> 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.

Why do you want to do this?  Exec and eval should -not- be used for
this unless you are specifically creating a system allows arbitrary
code execution.  What's wrong with using a dictionary?  It's much safer
than allowing arbitrary names to be injected into a namespace.




More information about the Python-list mailing list