pretty basic: get variable name from list of strings?
Andrew Koenig
ark at research.att.com
Mon Jul 29 18:35:31 EDT 2002
chris> in the specific,
chris> if I have a list
chris> animals = ['horse_0', 'horse_1']
chris> horsenames = ['smokey', 'silver']
chris> how do assign variables with those strings as names?
chris> ie, I want
chris> horse_0 = "smokey"
chris> horse_1= "silver"
chris> but if I write animals[0] = "smokey", it replaces the value, it
chris> doesn't assign it. What I want is like assign() or eval() in other
chris> languages.
chris> you can imagine i am trying to iterate over large indexes of
chris> animals[i] = 'horse_' + str(i)
chris> and then assign them from a value list
The first question to answer is why you want to have a whole bunch
of variable names instead of using a dict.
--
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark
More information about the Python-list
mailing list