inline comparison

sam sam.wun at authtec.com
Sun Mar 20 16:22:39 CET 2005


Tim Roberts wrote:

> sam <sam.wun at authtec.com> wrote:
> 
> 
>>Hi,
>>
>>I got the the following syntax error in comparison:
>>  File "/usr/local/work/myparser.py", line 85
>>    if ( (m=self.macro_parser.match (d)) != None ):
>>           ^
>>SyntaxError: invalid syntax
>>
>>How can I get around wtih this? I don't want to break down this 
>>comparison in two steps.
> 
> 
> Sorry, you have to.  Assignment statements are not expressions in Python.  
> 
>     m = self.macro_parser.match(d)
>     if m:
>         xxx
> 
This is very bad to me, I will need to write some cumbersome syntax as 
follow:
        for d in self.data:
             m = self.macro_parser.match (d)) != None ):
             if (m == None):
                m_nat = self.a_parser.match (d)
                if (m_a == None):
                   m_rdr = self.b_parser.match (d)
                   if (m_b == None):
                       m_c = self.c_parser.match (d)
                       if (m_c == None):
                          m_d = self.d_parser.match (d)
                          if (m_d == None):
                             m_e = self.e_parser.match (d)
                             if (m_e == None):
  				.....


> You know the outer parentheses are not necessary, right?




More information about the Python-list mailing list