[Tutor] Single pass through if loop yeilds multiple results...
Doug.Shawhan@gecits.ge.com
Doug.Shawhan@gecits.ge.com
Wed Nov 27 17:12:01 2002
I am performing lookups with anydbm.
For some reason when this is run:
elif act == 'Lookup Part By Description':
if form.has_key('desc'):
part=form['desc'].value
print '''<hr><table><tr>'''
for each in db.keys():
if string.find(string.upper(db[each]), string.upper(part))
!= -1:
ret_table='''<td bgcolor=gray>
<font face=arial size=2 color=white> %s
</font></td>
<td><font face=arial size=2
color=black>%s</td><tr>'''%(each,db[each] )
print ret_table
else:
print 'Lookup Failed.'
I will get multiple returns with the same key. The identical keys seem to be
randomly spread throughout the output. Since it only marches once through
db.keys(), how does the identical output happen?
Output looks like this:
------------------snip----------------------------
26P9564 IBM, T20, LCD cover kit
02k5545 IBM, T20, Key Board
02k6626 IBM, T20, Battery
08k9533 IBM, T20, HDD
05k9207 IBM, T20, FDD
22p6753 IBM, T20, NIC Card
05k9188 IBM, T20, DVD
10l1402 IBM, T20, Inverter
02k6665/02k6677 IBM, T20, AC Adapter
27l0519 IBM, T20, LCD Cables
26p8023 IBM, T20, I/O Card
13h5264 IBM, T20, Power Cord
20l0265 IBM, T20, Memory 128mb
05K9568 IBM, T20, LCD Display
10l1402 IBM, T20, Inverter
27l0519 IBM, T20, LCD Cables
13h5264 IBM, T20, Power Cord
26p8023 IBM, T20, I/O Card
08k9533 IBM, T20, HDD
12p3360 IBM, T20, System Board
12p3360 IBM, T20, System Board
22p6753 IBM, T20, NIC Card
02k6665/02k6677 IBM, T20, AC Adapter
05k9188 IBM, T20, DVD
02k5545 IBM, T20, Key Board
26P9564 IBM, T20, LCD cover kit
02k6626 IBM, T20, Battery
20l0265 IBM, T20, Memory 128mb
05K9568 IBM, T20, LCD Display
05k9207 IBM, T20, FDD
---------------snip--------------------------------------------