Cascading ifs

Ernesto García García titogarcia_nospamplease_ at gmail.com
Mon Apr 2 15:20:55 CEST 2007


Hi experts,

How would you do this without the more and more indenting cascade of ifs?:

match = my_regex.search(line)
if match:
   doSomething(line)
else:
   match = my_regex2.search(line)
   if match:
     doSomething2(line)
   else:
     match = my_regex3.search(line)
     if match:
       doSomething3(line)

etc.

Thanks in advance and regards,
Ernesto



More information about the Python-list mailing list