On Feb 27, 1:51?pm, Steven D'Aprano <steve +comp.lang.pyt... at pearwood.info> wrote:
Ints and floats can be compared directly, no need to convert the int to a
Ah, cheers. You can see how often I use the two interchangeably :)
Please provide a non-contrived use case of an "infinite string".
Any lazy stream of characters that potentially goes on forever could be
considered an infinite string. But that's not what Rick is talking about.
He's talking about having a pair of special values, say, BIGGEST and
SMALLEST, which compare larger and smaller to any other value, regardless
of type and including strings, not literally a string with an infinite
number of characters.
Yeah, my point was more to highlight Rick's laziness in co-opting a
defined term - INFINITE - and trying to use it to mean something else
that he couldn't express clearly. His original post stressed numeric
comparison, the feature creep to include all other types happened
later. Not the sort of thing we've come to expect from the resident
linguist extraordinaire :)
I can see some value for this as a convenience, but not enough to make it
a built-in language feature.
For me, it feels like a step backwards to comparing different types:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unorderable types: int() < str()
Every developer should have at least one
utility module with all the trivial code snippets they frequently use.
This belongs in there.
Agreed. Especially when it's so trivial:
def __init__(self, value=None, always_greater=False):
self.value = value
self.always_greater = always_greater
def __cmp__(self, other):
return True if self.always_greater else self.value.__cmp__(other)
upper = Bound(100)
101 > upper
infinite = Bound(always_greater=True)
101 > infinite