Creating variables from dicts

Luis M. González luismgz at gmail.com
Tue Feb 23 23:44:10 EST 2010


On Feb 24, 1:15 am, Steven D'Aprano
<ste... at REMOVE.THIS.cybersource.com.au> wrote:
> On Tue, 23 Feb 2010 19:47:22 -0800, Luis M. González wrote:
> > 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 follows:
>
> >> >     locals().update( myDictionary )
>
> >> No you can't. Try it inside a function.
>
> >> --
> >> Steven
>
> > Sure. Inside a function I would use globals() instead. Although I don't
> > know if it would be a good practice...
>
> Er, how does using globals change the local variables?
>
> --
> Steven

Hmmm.... well, you tell me!
As I said, I don't know if this is the recomended way...

Luis



More information about the Python-list mailing list