I'm not sure if it's exactly what you need, but here's something that may come close.<br><br><div><span class="gmail_quote">On 6/5/06, <b class="gmail_sendername">Peter Jessop</b> <<a href="mailto:pjlists@gmail.com">pjlists@gmail.com
</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">The best way to explain my problem is with an example<br><br>f0_n = "field0"
<br>f0_v ="value0"<br>f1_n="field1"<br>f1_v="value1"<br>...<br><br>f100_n = "field100"<br>f100_v = "value100"</blockquote><div><br>Ok, I'm going to recreate this fake example, rather than typing it all out :-)
<br>for i in range(101):<br> print 'f%d_n = "field%d"'%(i, i)<br> print 'f%d_v = "value%d"'%(i, i)<br><br>I then cut-and-paste the result in the editor window and start again.<br><br><br>data1 = ["(f%d_n, f%d_v)"%(i, i) for i in range(101)]
<br><br>print data1<br># This shows: ['(f0_n, f0_v)', '(f1_n, f1_v)', '(f2_n, f2_v)' ... '(f100_n, f100_v)']<br><br>data2 = ','.join(data1)<br>data2 = '[' + data2 + ']'<br>print eval(data2)<br><br>The result is: [('field0', 'value0'), ('field1', 'value1'), ..., ('field100', 'value100')]
<br>i.e. it is a list of 2ples that contains the values of the variable, rather than the variables themselves. For most applications, this should be the same thing, right?<br><br>André<br> </div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I now want to define a list of 2ples of the form<br><br>[(f0_n,f0_v),(f1_n,f1_v),...,(f100_n,f100_v)]<br><br>I wish to define the list using a for loop, i.e.<br><br>data = [ ]<br>for i in xrange(1,101):<br> data = data.append
((f %i _n, f %i_v))<br><br>I have put the % sign above. Obviously it is not like that but how<br>does one do it?<br>The aim is to reference the s variable whose name is the string that I<br>create concatenating "f" + str(i)+"_n" and "f"+str(i)+"_v"
<br><br>Thanks<br><br>Peter Jessop<br>_______________________________________________<br>Tutor maillist - <a href="mailto:Tutor@python.org">Tutor@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/tutor">
http://mail.python.org/mailman/listinfo/tutor</a><br></blockquote></div><br>