I'm looking for a Python object which is guaranteed to compare greater than any given int
. It should be portable, platform-independent and work on both Python 2.7+ and 3.x.
For example:
x = float('inf')
while True:
n = next(my_gen)
if my_calc(n):
x = min(n, x)
if my_cond(x):
break
Here I've used float('inf')
for this purpose because it seems to behave correctly. But this feels dirty, because I think it relies on some underlying float specification and I don't know whether that's going to be platform dependent or break in unexpected ways.
I'm aware that I could create my own class and define the comparison operators, but I thought there might be an existing built-in way.
Is it safe to use float('inf')
like this? Is there a less ugly way of creating this "biggest integer"?