Python __builtin__ 模块,cmp() 实例源码

我们从Python开源项目中,提取了以下17个代码示例,用于说明如何使用__builtin__.cmp()

项目:NeoAnalysis    作者:neoanalysis    | 项目源码 | 文件源码
def cmpToKey(mycmp):
    'Convert a cmp= function into a key= function'
    class K(object):
        def __init__(self, obj, *args):
            self.obj = obj
        def __lt__(self, other):
            return mycmp(self.obj, other.obj) < 0
        def __gt__(self, other):
            return mycmp(self.obj, other.obj) > 0
        def __eq__(self, other):
            return mycmp(self.obj, other.obj) == 0
        def __le__(self, other):
            return mycmp(self.obj, other.obj) <= 0
        def __ge__(self, other):
            return mycmp(self.obj, other.obj) >= 0
        def __ne__(self, other):
            return mycmp(self.obj, other.obj) != 0
    return K
项目:NeoAnalysis    作者:neoanalysis    | 项目源码 | 文件源码
def cmpToKey(mycmp):
    'Convert a cmp= function into a key= function'
    class K(object):
        def __init__(self, obj, *args):
            self.obj = obj
        def __lt__(self, other):
            return mycmp(self.obj, other.obj) < 0
        def __gt__(self, other):
            return mycmp(self.obj, other.obj) > 0
        def __eq__(self, other):
            return mycmp(self.obj, other.obj) == 0
        def __le__(self, other):
            return mycmp(self.obj, other.obj) <= 0
        def __ge__(self, other):
            return mycmp(self.obj, other.obj) >= 0
        def __ne__(self, other):
            return mycmp(self.obj, other.obj) != 0
    return K
项目:imagepyqt    作者:Image-Py    | 项目源码 | 文件源码
def cmpToKey(mycmp):
    'Convert a cmp= function into a key= function'
    class K(object):
        def __init__(self, obj, *args):
            self.obj = obj
        def __lt__(self, other):
            return mycmp(self.obj, other.obj) < 0
        def __gt__(self, other):
            return mycmp(self.obj, other.obj) > 0
        def __eq__(self, other):
            return mycmp(self.obj, other.obj) == 0
        def __le__(self, other):
            return mycmp(self.obj, other.obj) <= 0
        def __ge__(self, other):
            return mycmp(self.obj, other.obj) >= 0
        def __ne__(self, other):
            return mycmp(self.obj, other.obj) != 0
    return K

## python2_3
项目:NeoAnalysis    作者:neoanalysis    | 项目源码 | 文件源码
def cmp(a,b):
        if a>b:
            return 1
        elif b > a:
            return -1
        else:
            return 0
项目:NeoAnalysis    作者:neoanalysis    | 项目源码 | 文件源码
def cmp(a,b):
        if a>b:
            return 1
        elif b > a:
            return -1
        else:
            return 0
项目:hakkuframework    作者:4shadoww    | 项目源码 | 文件源码
def cmp(x, y):
        """
        cmp(x, y) -> integer

        Return negative if x<y, zero if x==y, positive if x>y.
        """
        return (x > y) - (x < y)
项目:fandango    作者:tango-controls    | 项目源码 | 文件源码
def decimate_custom(seq,cmp=None,pops=None,keeptime=3600*1.1):
    """ 
    @NOTE: Although faster, filter_array does a better decimation for trends
    It will remove all values from a list that doesn't provide information.
    In a set of X consecutive identical values it will remove all except 
    the first and the last.
    A custom compare method can be passed as argument
    :param seq: a list of (timestamp,value) values
    """
    if len(seq)<3: return seq
    if len(seq[0])<2: return seq
    import __builtin__
    cmp = cmp or __builtin__.cmp
    pops = pops if pops is not None else []
    while pops: pops.pop() 
    x0,x1,x2 = seq[0],seq[1],seq[2]

    for i in range(len(seq)-2):

        if not cmp(x0[1],seq[i+1][1]) and not cmp(seq[i+1][1],seq[i+2][1]):
            pops.append(i+1)
        else: 
            x0 = seq[i+1]

    for i in reversed(pops):
        seq.pop(i)
    return seq
项目:imagepyqt    作者:Image-Py    | 项目源码 | 文件源码
def cmp(a,b):
        if a>b:
            return 1
        elif b > a:
            return -1
        else:
            return 0
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
def cmp(x, y):
        """
        cmp(x, y) -> integer

        Return negative if x<y, zero if x==y, positive if x>y.
        """
        return (x > y) - (x < y)
项目:islam-buddy    作者:hamir    | 项目源码 | 文件源码
def cmp(x, y):
        """
        cmp(x, y) -> integer

        Return negative if x<y, zero if x==y, positive if x>y.
        """
        return (x > y) - (x < y)
项目:FightstickDisplay    作者:calexil    | 项目源码 | 文件源码
def cmp(x, y):
        """
        cmp(x, y) -> integer

        Return negative if x<y, zero if x==y, positive if x>y.
        """
        return (x > y) - (x < y)
项目:cryptogram    作者:xinmingzhang    | 项目源码 | 文件源码
def cmp(x, y):
        """
        cmp(x, y) -> integer

        Return negative if x<y, zero if x==y, positive if x>y.
        """
        return (x > y) - (x < y)
项目:Repobot    作者:Desgard    | 项目源码 | 文件源码
def cmp(x, y):
        """
        cmp(x, y) -> integer

        Return negative if x<y, zero if x==y, positive if x>y.
        """
        return (x > y) - (x < y)
项目:UMOG    作者:hsab    | 项目源码 | 文件源码
def cmp(x, y):
        """
        cmp(x, y) -> integer

        Return negative if x<y, zero if x==y, positive if x>y.
        """
        return (x > y) - (x < y)
项目:beepboop    作者:nicolehe    | 项目源码 | 文件源码
def cmp(x, y):
        """
        cmp(x, y) -> integer

        Return negative if x<y, zero if x==y, positive if x>y.
        """
        return (x > y) - (x < y)
项目:hackathon    作者:vertica    | 项目源码 | 文件源码
def cmp(x, y):
        """
        cmp(x, y) -> integer

        Return negative if x<y, zero if x==y, positive if x>y.
        """
        return (x > y) - (x < y)
项目:yatta_reader    作者:sound88    | 项目源码 | 文件源码
def cmp(x, y):
        """
        cmp(x, y) -> integer

        Return negative if x<y, zero if x==y, positive if x>y.
        """
        return (x > y) - (x < y)