From dictionary keys to variables

Michael Foord fuzzyman at gmail.com
Tue Oct 12 03:14:05 EDT 2004


Timothy Babytch <tim at zeos.net> wrote in message news:<ckecld$1qun$1 at news.dg.net.ua>...
> Michael Foord wrote:
> Why cheat? There is legal way to do that:
> 
> for entry in valuelist:
> 	globals()[entry] = config[entry]
> 
> > Now is there any reason not to 'cheat' and use __main__.__dict__ to
> > create the variables ?
> > 
> > valuelist = ['name1', 'name2', 'name3'....]
> > config = ConfigObj(filename, configspec=valuelist)
> > import __main__
> > for entry in valuelist:
> >         __main__.__dict__[entry] = config[entry]
> 
> 

Ahh... I didn't realise you could do assignment into globals()......... 

Thanks

Fuzzy

http://www.voidspace.org.uk/atlantibots/pythonutils.html

> 
> 
> -- 
> Timothy Babytch



More information about the Python-list mailing list