I am trying to find the functional equivalent of logical operators in Python (e.g. and / or / not). I thought I found them in a module operator, but the behavior is different from the others.
For example, the operator andexecutes the behavior that I want, while it operator.and_seems to require explicit type comparison, otherwise 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 a module operatorbut contains functions that exactly match the behavior of the logic of the Python operator?
Cerin source
share