def lrange(num1, num2=None, step=1):
"""
Allows iteration over arbitrary numbers instead of dword long numbers.
Credits go to:
http://stackoverflow.com/questions/2187135/range-and-xrange-for-13-digit-numbers-in-python
http://stackoverflow.com/users/263162/ricardo-cardenes
"""
op = operator.__lt__
if num2 is None:
num1, num2 = 0, num1
if num2 < num1:
if step > 0:
num1 = num2
op = operator.__gt__
elif step < 0:
num1 = num2
while op(num1, num2):
yield num1
num1 += step
python类__gt__()的实例源码
def get_operator(op):
if not op: return None
if "ge" in op or ">=" in op:
opr = operator.__ge__
elif "gt" in op or ">" in op:
opr = operator.__gt__
elif "le" in op or "<=" in op:
opr = operator.__le__
elif "lt" in op or "<" in op:
opr = operator.__lt__
elif "eq" in op or "=" in op or "==" in op:
opr = operator.eq
elif "ne" in op or "!=" in op or "<>" in op:
opr = operator.ne
return opr
def __gt__(self, rhs):
return op_relational(self, rhs, operator.__gt__)
# Aliases
def __gt__(self, rhs):
return op_relational(self, rhs, operator.__gt__)
# Aliases
def __gt__(self, other):
return self.x > other
def __gt__(self, other):
return Vector([a > b for a, b in zip(self.data, self.__cast(other))])
def test_misbehavin(self):
class Misb:
def __lt__(self_, other): return 0
def __gt__(self_, other): return 0
def __eq__(self_, other): return 0
def __le__(self_, other): self.fail("This shouldn't happen")
def __ge__(self_, other): self.fail("This shouldn't happen")
def __ne__(self_, other): self.fail("This shouldn't happen")
a = Misb()
b = Misb()
self.assertEqual(a<b, 0)
self.assertEqual(a==b, 0)
self.assertEqual(a>b, 0)
def __gt__(self, other):
return self.x > other
def __gt__(self, other):
return Vector([a > b for a, b in zip(self.data, self.__cast(other))])
def test_misbehavin(self):
class Misb:
def __lt__(self_, other): return 0
def __gt__(self_, other): return 0
def __eq__(self_, other): return 0
def __le__(self_, other): self.fail("This shouldn't happen")
def __ge__(self_, other): self.fail("This shouldn't happen")
def __ne__(self_, other): self.fail("This shouldn't happen")
def __cmp__(self_, other): raise RuntimeError, "expected"
a = Misb()
b = Misb()
self.assertEqual(a<b, 0)
self.assertEqual(a==b, 0)
self.assertEqual(a>b, 0)
self.assertRaises(RuntimeError, cmp, a, b)
def __gt__(self, other):
return self.x > other
def __gt__(self, other):
return Vector([a > b for a, b in zip(self.data, self.__cast(other))])
def test_misbehavin(self):
class Misb:
def __lt__(self_, other): return 0
def __gt__(self_, other): return 0
def __eq__(self_, other): return 0
def __le__(self_, other): self.fail("This shouldn't happen")
def __ge__(self_, other): self.fail("This shouldn't happen")
def __ne__(self_, other): self.fail("This shouldn't happen")
def __cmp__(self_, other): raise RuntimeError, "expected"
a = Misb()
b = Misb()
self.assertEqual(a<b, 0)
self.assertEqual(a==b, 0)
self.assertEqual(a>b, 0)
self.assertRaises(RuntimeError, cmp, a, b)
def __gt__(self, other):
return self.x > other
def __gt__(self, other):
return Vector([a > b for a, b in zip(self.data, self.__cast(other))])
def test_misbehavin(self):
class Misb:
def __lt__(self_, other): return 0
def __gt__(self_, other): return 0
def __eq__(self_, other): return 0
def __le__(self_, other): self.fail("This shouldn't happen")
def __ge__(self_, other): self.fail("This shouldn't happen")
def __ne__(self_, other): self.fail("This shouldn't happen")
a = Misb()
b = Misb()
self.assertEqual(a<b, 0)
self.assertEqual(a==b, 0)
self.assertEqual(a>b, 0)
def __gt__(self, other):
return self.x > other
def __gt__(self, other):
return Vector([a > b for a, b in zip(self.data, self.__cast(other))])
def test_misbehavin(self):
class Misb:
def __lt__(self_, other): return 0
def __gt__(self_, other): return 0
def __eq__(self_, other): return 0
def __le__(self_, other): self.fail("This shouldn't happen")
def __ge__(self_, other): self.fail("This shouldn't happen")
def __ne__(self_, other): self.fail("This shouldn't happen")
def __cmp__(self_, other): raise RuntimeError, "expected"
a = Misb()
b = Misb()
self.assertEqual(a<b, 0)
self.assertEqual(a==b, 0)
self.assertEqual(a>b, 0)
self.assertRaises(RuntimeError, cmp, a, b)
def __gt__(self, other):
return self.x > other
def __gt__(self, other):
return Vector([a > b for a, b in zip(self.data, self.__cast(other))])
def test_misbehavin(self):
class Misb:
def __lt__(self_, other): return 0
def __gt__(self_, other): return 0
def __eq__(self_, other): return 0
def __le__(self_, other): self.fail("This shouldn't happen")
def __ge__(self_, other): self.fail("This shouldn't happen")
def __ne__(self_, other): self.fail("This shouldn't happen")
a = Misb()
b = Misb()
self.assertEqual(a<b, 0)
self.assertEqual(a==b, 0)
self.assertEqual(a>b, 0)
def __gt__(self, other):
return self.x > other
def __gt__(self, other):
return Vector([a > b for a, b in zip(self.data, self.__cast(other))])
def test_misbehavin(self):
class Misb:
def __lt__(self_, other): return 0
def __gt__(self_, other): return 0
def __eq__(self_, other): return 0
def __le__(self_, other): self.fail("This shouldn't happen")
def __ge__(self_, other): self.fail("This shouldn't happen")
def __ne__(self_, other): self.fail("This shouldn't happen")
def __cmp__(self_, other): raise RuntimeError, "expected"
a = Misb()
b = Misb()
self.assertEqual(a<b, 0)
self.assertEqual(a==b, 0)
self.assertEqual(a>b, 0)
self.assertRaises(RuntimeError, cmp, a, b)
def __gt__(self, other):
return self.x > other
def __gt__(self, other):
return Vector([a > b for a, b in zip(self.data, self.__cast(other))])
def test_misbehavin(self):
class Misb:
def __lt__(self_, other): return 0
def __gt__(self_, other): return 0
def __eq__(self_, other): return 0
def __le__(self_, other): self.fail("This shouldn't happen")
def __ge__(self_, other): self.fail("This shouldn't happen")
def __ne__(self_, other): self.fail("This shouldn't happen")
a = Misb()
b = Misb()
self.assertEqual(a<b, 0)
self.assertEqual(a==b, 0)
self.assertEqual(a>b, 0)
def greaterThan(typeA, typeB):
if operator.__gt__(typeA.number.getNum(), typeB.number.getNum()):
return True
else:
return False
def __gt__(self, _):
return False