How best to write this if-else?

Ingo Wilken Ingo.Wilken at Informatik.Uni-Oldenburg.DE
Sat Apr 21 16:49:55 EDT 2001


Roy Smith <roy at panix.com> writes:
>e1 = re.compile ('...')
>e2 = re.compile ('...')
>e3 = re.compile ('...')
>line = file.readline()

for e in [e1, e2, e3]:
    m = e.match(line)
    if m:
        text = m.group(1)
        break
else:
    no match found

Note that the 'else' belongs to the 'for', not to the 'if'.

Regards,
Ingo
-- 
"I like VIM because, when I ask a question in this NG, I get a one-line
 answer. With xemacs, I get a 1Kb lisp script with bugs in it ;-)"
    -- wroot at my-deja.com in comp.editors, <948toi$ttt$1 at nnrp1.deja.com>



More information about the Python-list mailing list