[Tutor] Reference a variable from a string whose value is the name of the variable
Peter Jessop
pjlists at gmail.com
Tue Jun 6 00:47:32 CEST 2006
The best way to explain my problem is with an example
f0_n = "field0"
f0_v ="value0"
f1_n="field1"
f1_v="value1"
...
f100_n = "field100"
f100_v = "value100"
I now want to define a list of 2ples of the form
[(f0_n,f0_v),(f1_n,f1_v),...,(f100_n,f100_v)]
I wish to define the list using a for loop, i.e.
data = [ ]
for i in xrange(1,101):
data = data.append((f %i _n, f %i_v))
I have put the % sign above. Obviously it is not like that but how
does one do it?
The aim is to reference the s variable whose name is the string that I
create concatenating "f" + str(i)+"_n" and "f"+str(i)+"_v"
Thanks
Peter Jessop
More information about the Tutor
mailing list