bruno at modulix wrote:

> Almost :
> 
> a = b()
> if a:
>   do_stuff_with_b(a)
> else:
>   a = c()
>   if a:
>     do_stuff_with_c(a)
>   else:
>     do_other_stuff()
> 
> 
> Now there are probably better ways to write this, but this would require
> more knowledge about your real code.

if there are more than a couple of options you can generalise code such as 
this to use a for loop:

for guard, action in [
    (b, do_stuff_with_b),
    (c, do_stuff_with_c),
    ]:
    if guard():
        action(a)
        break
else:
    do_other_stuff()
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to