pretty basic: get variable name from list of strings?

chris
Mon Jul 29 18:18:36 EDT 2002


in the specific,

if I have a list

animals = ['horse_0', 'horse_1']
horsenames = ['smokey', 'silver']

how do assign variables with those strings as names? 

ie, I want  
horse_0 = "smokey"
horse_1= "silver"

but if I write animals[0] = "smokey", it replaces the value, it
doesn't assign it.  What I want is like assign() or eval() in other
languages.

you can imagine i am trying to iterate over large indexes of
animals[i] = 'horse_' + str(i)
and then assign them from a value list

or even screw the variable list and instead iterate over the
value list
'horse_' + str(i) = horsenames[i].

but i'm missing the key command to tell python "treat this string like
code and not a string."

thx,
chris



More information about the Python-list mailing list