test assignmet problem

Paolo Pantaleo paolopantaleo at gmail.com
Mon Apr 24 16:07:26 EDT 2006


2006/4/23, Paul McGuire <ptmcg at austin.rr._bogus_.com>:
>
> "Paolo Pantaleo" <paolopantaleo at gmail.com> wrote in message
> news:mailman.4903.1145802299.27775.python-list at python.org...
> So I tried this
>
>         if(not (attr=global_re.match(line)) ):
>             break
>
> it says  invalid syntax [on the =]
>   ... because this syntax is not valid ...
>
> so it is not possible to do test and assignment in C style?
>   ... no it's not, see
> http://www.python.org/doc/faq/general/#why-can-t-i-use-an-assignment-in-an-expression
>
> how can I write this otherwise?
>   ... is this so bad?...
>
>         attr=global_re.match(line)
>         if not attr:
>             break
>
>   ... or, since you don't seem to be doing much with attr, you could just do
>
>         if not global_re.match(line):
>             break
>
>   ... and get rid of all those distracting ()'s!
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

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
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


the other is


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

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


PAolo
--
if you have a minute to spend please visit my photogrphy site:
http://mypic.co.nr



More information about the Python-list mailing list