I'm trying to find the functional equivalent of logic statements in Python (e.g. and/or/not). I thought I had found them in the operator module, but the behavior is remarkable different.
For example, the and statement does the behavior I want, whereas operator.and_ seems to requir an explicit type comparison, or else it throws a TypeError exception.
>>> from operator import *
>>> class A: pass
...
>>> and_(A(), True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for &: 'instance' and 'bool'
>>> A() and True
True
Is there something like the operator module, but containing functions that match the behavior of Python's statement logic exactly?
def and_(p1,p2): return p1 and p2