<br><br><div><span class="gmail_quote">On 8/15/07, <b class="gmail_sendername">mfglinux</b> <<a href="mailto:mfglinux@gmail.com">mfglinux@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;">
<br>#Let's say x=3, then Period definition is<br>Period=Slab(Material1(12.5)+Material2(25)+Material3(12.5)) #Slab is a<br>python class<br><br>I dont know how to automatize last piece of code for any x<br></blockquote>
</div><br><br><br>Hello,<br><br>you could use exec to create on the fly the variables as you need them (but be aware that the use of exec can be dangerous and is probably not needed), or you could add the proper name to a relevant dictionary (for example, locals() ). Something like
<br><br>for counter in xrange(3):<br> locals()["Material" + str(counter)] = Material(12.5)<br><br> <br>But if you need the variables only for calling Slab, you could write something like:<br><br>material_number = 3
<br>material_list = [Material(12.5) for x in xrange(0, counter)]<br>Period = Slab(sum(material_list))<br><br>bye,<br>francesco<br>