sys.maxint in Python 3

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Mon Apr 21 11:44:53 CEST 2008


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



More information about the Python-list mailing list