test assignmet problem

Paul McGuire ptmcg at austin.rr._bogus_.com
Sun Apr 23 10:43:14 EDT 2006


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





More information about the Python-list mailing list