[Tutor] Re: creating variables from the 'key' of a dictionary. (original) (raw)

Andrei project5 at redrival.net
Fri Jul 2 15:42:13 EDT 2004


Larry Blair wrote on Fri, 2 Jul 2004 10:16:54 -0700:

> _My question is there a way to create a variable with the name of the key in_ > _a dictionary i.e._ >> _para = {}_ > _para['sourceserver'] = 'cm05'_ >> _at this point I want to create a variable with the name sourceserver and a_ > _value of 'cm05'._

Use the globals() dictionary (it contains a dictionary mapping all variable names to corresponding objects):

globals()['sourceserver'] = 'cm05' sourceserver 'cm05'

But I think Jeff's suggestions for a settings module shared by all your apps is a better idea.

-- Yours,

Andrei

===== Real contact info (decode with rot13): cebwrpg5 at jnanqbb.ay. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq gur yvfg, fb gurer'f ab arrq gb PP.



More information about the Tutor mailing list