test assignmet problem

bruno at modulix onurb at xiludom.gro
Tue Apr 25 05:31:49 EDT 2006


Paolo Pantaleo wrote:
(snip)
> Thnx for the help,
> actually the problme is not solved
> 
> i have [well I want to do...] something like:
> 
> if a=b():
>    do stuff with a
> else if a=c():
>    do stuff with b

where does this 'b' come from ?

> else:
>    do other stuff
> 
> well, two solutions are
> 
> a1=b()
> a2=c()
> 
> if a1:
>    do stuff with a1
> else if a2:
>    do stuff with a2
> else:
>    do other stuff

if the call to b() returns a non-false value, the call to c() is useless.

> 
> the other is
> 
> 
> if b():
>    a=b()
>    do stuff with a
> else if c():
>    a=c()
>    do stuff with b
> else:
>    do other stuff

You still have useless function calls.

> Even if none is exactly the same about:
>  * the number of times the b() and c() functions are executed
>  * the final value of a
> 
> I think the right one is:
> 
> a=b()
> if a:
>    do stuff with a
> else:
>    a=c()
>    if a=c():
>        do stuff with b
>    else:
>         do other stuff

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.

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list