PyWart: Language missing maximum constant of numeric types!

Mel Wilson mwilson at the-wire.com
Fri Feb 24 10:21:45 EST 2012


Rick Johnson wrote:

> I get sick and tired of doing this!!!
> 
> if maxlength == UNLIMITED:
>     allow_passage()
> elif len(string) > maxlength:
>     deny_passage()
> 
> What Python needs is some constant that can be compared to ANY numeric
> type and that constant will ALWAYS be larger!

Easily fixed:



class Greatest (object):
    def __cmp__ (self, other):
        if isinstance (other, Greatest):
            return 0
        return 1
        
    def __hash__ (self):
        return id (Greatest)
        
class Least (object):
    def __cmp__ (self, other):
        if isinstance (other, Least):
            return 0
        return -1
        
    def __hash__ (self):
        return id (Least)



	Mel.



More information about the Python-list mailing list