inline comparison

Peter Hansen peter at
Sun Mar 20 04:38:58 CET 2005

sam wrote:
> I got the the following syntax error in comparison:
>   File "/usr/local/work/", line 85
>     if ( (m=self.macro_parser.match (d)) != None ):
>            ^
> SyntaxError: invalid syntax
> How can I get around wtih this? 

Break the comparison into two steps.

 > I don't want to break down this comparison in two steps.

Why not?  Assignments are statements in Python, and
you can't have a statement inside an expression like
you are trying to do.  C can do it, and many other
languages, but not all, and not Python.  There are
alternatives involving creating your own class, but
why bother?  Just split the code...


More information about the Python-list mailing list