I'm trying to insert a variable mathematical operator into a if statement, an example of what I'm trying to achieve in parsing user-supplied mathematical expressions:
maths_operator = "=="
if "test" maths_operator "test":
print "match found"
maths_operator = "!="
if "test" maths_operator "test":
print "match found"
else:
print "match not found"
obviously the above fails with SyntaxError: invalid syntax
. I've tried using exec and eval but neither work in an if statement, what options do I have to get around this?