inline comparison
Peter Hansen
peter at engcorp.com
Sat Mar 19 22:38:58 EST 2005
sam wrote:
> 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?
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...
-Peter
More information about the Python-list
mailing list