Ernesto García García wrote:
> 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.

tbl = [(my_regex, doSomething), (my_regex2, doSomething2), (my_regex3, 
doSomething3)]
for regex, fun in tbl:
     match = regexp.match(line)
     if match:
        fun(line)
        break

w.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to