In some algorithms a sentinel value may be useful, so for Python 3.x
sys.maxint may be replaced by an improvement of the following infinite
and neginfinite singleton objects:

class Infinite(object):
    def __repr__(self): return "infinite"
    def __cmp__(self, other):
        if other is infinite: return 0
        if other is neginfinite: return 1
        other + 1 # type control
        return 1
infinite = Infinite()

class NegInfinite(object):
    def __repr__(self): return "neginfinite"
    def __cmp__(self, other):
        if other is neginfinite: return 0
        if other is infinite: return -1
        other + 1 # type control
        return -1
neginfinite = NegInfinite()

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to