test assignmet problem

Duncan Booth duncan.booth at invalid.invalid
Sun Apr 23 10:36:02 EDT 2006


Paolo Pantaleo wrote:

> So I tried this
> 
>         if(not (attr=global_re.match(line)) ):
>             break
> 
> it says  invalid syntax [on the =]
> so it is not possible to do test and assignment in C style?
> how can I write this otherwise?
> 
With fewer parentheses for a start, but all you have to do here is to do 
the assignment and the test on separate lines:

    attr = global_re.match(line)
    if not attr:
        break

In other cases you may have to work a bit harder to restructure your code.



More information about the Python-list mailing list