Creating variables from dicts
bruno.42.desthuilliers at websiteburo.invalid
Wed Feb 24 12:40:22 CET 2010
Luis M. González a écrit :
> On Feb 23, 10:41 pm, Steven D'Aprano
> <ste... at REMOVE.THIS.cybersource.com.au> wrote:
>> On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. González wrote:
>>> By the way, if you want the variables inside myDict to be free
>>> variables, you have to add them to the local namespace. The local
>>> namespace is also a dictionary "locals()". So you can update locals as
>>> locals().update( myDictionary )
>> No you can't. Try it inside a function.
> Sure. Inside a function I would use globals() instead.
> Although I don't know if it would be a good practice...
It's even worse than a bad practice. Hint : why is "globals" named
"globals" and not "locals" ?
More information about the Python-list