<div class="gmail_quote">On Fri, Dec 4, 2009 at 2:08 PM, Victor Subervi <span dir="ltr"><<a href="mailto:victorsubervi@gmail.com">victorsubervi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="gmail_quote"><div><div></div><div class="h5">On Fri, Dec 4, 2009 at 12:43 PM, MRAB <span dir="ltr"><<a href="mailto:python@mrabarnett.plus.com" target="_blank">python@mrabarnett.plus.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>Victor Subervi wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi;<br>
I have this code:<br>
 <br>
</blockquote></div>
[snip]<div><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
 As you can see in the supplied comments, when I loop through for table 'prescriptions', it only prints out the first element of each variable. When I loop through for table 'products', it prints out all of them! Why?<br>


<br>
</blockquote></div>
If you're serious about killing bugs, DON'T USE BARE EXCEPTS, especially<br>
ones which contain only "pass"!<br>
<br>
As for you're problem, it's not clear to me which one is behaving<br>
correctly. You should add more print statements to tell you where it is in the code, and then read through the output, checking the logic. Are<br>
the values what you expect? Is it following the route through the code<br>
that you expect?<br></blockquote></div></div><div><br>Forgive me, but I believe I already addressed your question. There are two tables: prescriptions and products, in that order, and both with (in this case) the exact same options. For some reason, when products goes through the loops, everything comes out exactly as expected. But when prescriptions goes through, only optionsCode[0] passes (there are two) and only optionsCode[0][0] goes through when there are 7. To restate that, both optionsCode[y] and all optionsCode[y][z] get correctly processed when 'products' goes through, but only one when 'prescriptions' goes through, and the options and options tables are identical! Here's the code again. I just now edited in a try statement to try to catch the bug, with no luck. Please advise.<div>
<div></div><div class="h5"><br>
V<br><br><br>  for table in tables:<br>    if table == 'products':<br>      optionsCode = optionsCodeProducts<br>      fromForm = prodsFromForm<br>    try:<br>      fn = getattr(options, table)<br>      fromForm = form.getfirst('%s-options' % table)<br>


      fromForm = string.split(fromForm[2:-2], "', '")<br>      optionsCode = fn(table, 'specificCode', fromForm)<br>    except:<br>      if table != 'products': # We recall we must add the products table fields to all tables.<br>


        optionsCode = optionsCodeProducts<br>    i = 0<br>    j = 0<br>    oldJ = 0<br>    try:<br>      y = 0<br>      while y < len(optionsCode):<br>        if table == 'prescriptions':<br>          print len(optionsCode) # prints '2'<br>


        for inputName in optionsCode[y]:<br>          if table == 'prescriptions':<br>            print len(optionsCode[y]) # prints '7'<br>            print inputName # prints 'Extra-small', which is only the first inputName in optionsCode[0]<br>


          if j != oldJ:<br>            i = 0<br>            oldJ = j<br>          x = '%s-%s%d' % (table, fromForm[y], i)<br>          try:<br>            x = form.getfirst(x)<br>            if x is not None:<br>
              ourInputNames.append('%s-%s' % (table, inputName))<br>          except:<br>            print 'Oops!'<br>          i += 1<br>        j += 1<br>        y += 1<br>    except:<br>      pass<br><br>
</div></div></div></div>
</blockquote></div><br>