Use the operator
module to get the corresponding functions for binary operations:
import operator
conversions = {
'==': operator.eq,
'+': operator.add
...
}
You would evaluate them like so:
op = conversions['==']
if op(stat, stat1):
...
Another method which is not as recommended is to use the underlying special method names to perform your operation:
conversions = {
'==': '__eq__',
'!=': '__ne__',
'>=': '__ge__',
...
}
Now when evaluating your code:
op = conversions['==']
if getattr(stat, op)(stat1):
...
To create a full conversions list, use this website to get the method names of binary operations - arithmetic ones like addition and logical ones like greater than.