test assignmet problem
Duncan Booth
duncan.booth at invalid.invalid
Tue Apr 25 05:51:54 EDT 2006
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()
More information about the Python-list
mailing list