to create variable from dict

hiral hiralsmaillist at gmail.com
Mon Mar 15 02:51:42 EDT 2010


On Mar 12, 8:02 pm, Jean-Michel Pichavant <jeanmic... at sequans.com>
wrote:
> Luis M. González wrote:
> > On Mar 12, 10:59 am,hiral<hiralsmaill... at gmail.com> wrote:
>
> >> Hi,
>
> >> Is there any way to create variables which name matches with dict key?
>
> >> For example:
> >> dict1 = {"abc":'1", "def":"2"}
>
> >> Now I am looking to have variable name abc and it's value be '1' etc.
>
> >> Pl. suggest.
>
> >> Thank you.
>
> > Check out this thread (very recent):
> >http://groups.google.com/group/comp.lang.python/browse_thread/thread/...
>
> > Short answer: you can update globals() with a dictionary, as follows:
>
> > globals().update( dict1 )
>
> > Then you'll have each key-value pair as variables in the global
> > namespace.
> > The question is: should you do it?
>
> > Luis
>
> The answer is known: no, he should not do it :o)
>
> JM- Hide quoted text -
>
> - Show quoted text -

Thanks for your explanations.



More information about the Python-list mailing list