我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用operator.__sub__()。
def __sub__(self, other): with self._lock: return operator.__sub__(self.__wrapped__, other)
def __sub__(self, rhs): return op_binary(self, rhs, operator.__sub__)
def __rsub__(self, lhs): return op_binary(lhs, self, operator.__sub__)
def __isub__(self, v): return self.op_binary_inplace(v, operator.__sub__)
def __rsub__(self, other): with self._lock: return operator.__sub__(other, self.__wrapped__)
def dms2decimal(degrees, minutes, seconds): op = operator.__add__ if degrees >= 0 else operator.__sub__ return reduce(op, [degrees, float(minutes)/60, float(seconds)/3600])
def subtract(typeA, typeB): return operator.__sub__(typeA.number.getNum(), typeB.number.getNum())
def test_sub(self): self._test_incompatible_types_fail(operator.__sub__) self.assertEqual(no_flags - no_flags, no_flags) self.assertEqual(no_flags - all_flags, no_flags) self.assertEqual(no_flags - f0, no_flags) self.assertEqual(no_flags - f1, no_flags) self.assertEqual(no_flags - f2, no_flags) self.assertEqual(no_flags - f01, no_flags) self.assertEqual(no_flags - f02, no_flags) self.assertEqual(no_flags - f12, no_flags) self.assertEqual(f0 - no_flags, f0) self.assertEqual(f0 - all_flags, no_flags) self.assertEqual(f0 - f0, no_flags) self.assertEqual(f0 - f1, f0) self.assertEqual(f0 - f2, f0) self.assertEqual(f0 - f01, no_flags) self.assertEqual(f0 - f02, no_flags) self.assertEqual(f0 - f12, f0) self.assertEqual(f01 - no_flags, f01) self.assertEqual(f01 - all_flags, no_flags) self.assertEqual(f01 - f0, f1) self.assertEqual(f01 - f1, f0) self.assertEqual(f01 - f2, f01) self.assertEqual(f01 - f01, no_flags) self.assertEqual(f01 - f02, f1) self.assertEqual(f01 - f12, f0) self.assertEqual(all_flags - no_flags, all_flags) self.assertEqual(all_flags - all_flags, no_flags) self.assertEqual(all_flags - f0, f12) self.assertEqual(all_flags - f1, f02) self.assertEqual(all_flags - f2, f01) self.assertEqual(all_flags - f01, f2) self.assertEqual(all_flags - f02, f1) self.assertEqual(all_flags - f12, f0)