Killing Another Bug

Victor Subervi victorsubervi at gmail.com
Fri Dec 4 13:23:24 EST 2009


On Fri, Dec 4, 2009 at 2:08 PM, Victor Subervi <victorsubervi at gmail.com>wrote:

> On Fri, Dec 4, 2009 at 12:43 PM, MRAB <python at mrabarnett.plus.com> wrote:
>
>> Victor Subervi wrote:
>>
>>> Hi;
>>> I have this code:
>>>
>>>
>> [snip]
>>
>>   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?
>>>
>>>  If you're serious about killing bugs, DON'T USE BARE EXCEPTS, especially
>> ones which contain only "pass"!
>>
>> As for you're problem, it's not clear to me which one is behaving
>> 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
>> the values what you expect? Is it following the route through the code
>> that you expect?
>>
>
> 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.
>
> V
>
>
>   for table in tables:
>     if table == 'products':
>       optionsCode = optionsCodeProducts
>       fromForm = prodsFromForm
>     try:
>       fn = getattr(options, table)
>       fromForm = form.getfirst('%s-options' % table)
>       fromForm = string.split(fromForm[2:-2], "', '")
>       optionsCode = fn(table, 'specificCode', fromForm)
>     except:
>       if table != 'products': # We recall we must add the products table
> fields to all tables.
>         optionsCode = optionsCodeProducts
>     i = 0
>     j = 0
>     oldJ = 0
>     try:
>       y = 0
>       while y < len(optionsCode):
>         if table == 'prescriptions':
>           print len(optionsCode) # prints '2'
>         for inputName in optionsCode[y]:
>           if table == 'prescriptions':
>             print len(optionsCode[y]) # prints '7'
>             print inputName # prints 'Extra-small', which is only the first
> inputName in optionsCode[0]
>           if j != oldJ:
>             i = 0
>             oldJ = j
>           x = '%s-%s%d' % (table, fromForm[y], i)
>           try:
>             x = form.getfirst(x)
>             if x is not None:
>               ourInputNames.append('%s-%s' % (table, inputName))
>           except:
>             print 'Oops!'
>           i += 1
>         j += 1
>         y += 1
>     except:
>       pass
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091204/f5ccdcc3/attachment-0001.html>


More information about the Python-list mailing list