From dictionary keys to variables

Timothy Babytch tim at zeos.net
Mon Oct 11 12:31:22 EDT 2004


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]




-- 
Timothy Babytch
--
You know you've achieved perfection in design,
  not when you have nothing more to add,
  but when you have nothing more to take away.



More information about the Python-list mailing list