I haven't found any use for them yet myself, but knowing that they
exist and still not using them troubles me, core python being quite
'small' after all.
-- Ville
It's good for searching, and saves mucking about with flags to achieve
the same effect. For example:
for item in list:
if item == match:
# Item found, take some action
item_found(item)
break
else:
# Item not found, take some other action
item_not_found()
Regards,
Derek.
for item in list:
if item == my_target:
print "found it"
process(item)
break
else:
print "not found"
while more_items():
item = get_next_item()
if item == my_target:
print "found it"
process(item)
break
else:
print "not found"
try:
item = lookup(database, key)
except KeyError:
print "not found"
else:
print "found"
process(item)
try:
handler = getattr(object, "handler")
except AttributeError:
print "no handler"
else:
handler(event)
# (etc)
</F>