当前位置: 首页>>代码示例>>Python>>正文


Python builtins.cmp方法代码示例

本文整理汇总了Python中past.builtins.cmp方法的典型用法代码示例。如果您正苦于以下问题:Python builtins.cmp方法的具体用法?Python builtins.cmp怎么用?Python builtins.cmp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在past.builtins的用法示例。


在下文中一共展示了builtins.cmp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_cmp

# 需要导入模块: from past import builtins [as 别名]
# 或者: from past.builtins import cmp [as 别名]
def test_cmp(self):
        self.assertEqual(cmp(-1, 1), -1)
        self.assertEqual(cmp(1, -1), 1)
        self.assertEqual(cmp(1, 1), 0)
        # verify that circular objects are not handled
        a = []; a.append(a)
        b = []; b.append(b)
        from UserList import UserList
        c = UserList(); c.append(c)
        self.assertRaises(RuntimeError, cmp, a, b)
        self.assertRaises(RuntimeError, cmp, b, c)
        self.assertRaises(RuntimeError, cmp, c, a)
        self.assertRaises(RuntimeError, cmp, a, c)
       # okay, now break the cycles
        a.pop(); b.pop(); c.pop()
        self.assertRaises(TypeError, cmp) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:18,代码来源:test_builtins.py

示例2: test_basic

# 需要导入模块: from past import builtins [as 别名]
# 或者: from past.builtins import cmp [as 别名]
def test_basic(self):
        data = range(100)
        copy = data[:]
        random.shuffle(copy)
        self.assertEqual(data, sorted(copy))
        self.assertNotEqual(data, copy)

        data.reverse()
        random.shuffle(copy)
        self.assertEqual(data, sorted(copy, cmp=lambda x, y: cmp(y,x)))
        self.assertNotEqual(data, copy)
        random.shuffle(copy)
        self.assertEqual(data, sorted(copy, key=lambda x: -x))
        self.assertNotEqual(data, copy)
        random.shuffle(copy)
        self.assertEqual(data, sorted(copy, reverse=1))
        self.assertNotEqual(data, copy) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:19,代码来源:test_builtins.py

示例3: __cmp__

# 需要导入模块: from past import builtins [as 别名]
# 或者: from past.builtins import cmp [as 别名]
def __cmp__(self, other):
        return cmp(self.prio, other.prio) 
开发者ID:jpmens,项目名称:mqttwarn,代码行数:4,代码来源:core.py

示例4: compare_versions

# 需要导入模块: from past import builtins [as 别名]
# 或者: from past.builtins import cmp [as 别名]
def compare_versions(v1, v2):
    try:
        return cmp(StrictVersion(v1), StrictVersion(v2))
    except ValueError:
        return cmp(LooseVersion(v1), LooseVersion(v2)) 
开发者ID:graphistry,项目名称:pygraphistry,代码行数:7,代码来源:util.py

示例5: test_cmp

# 需要导入模块: from past import builtins [as 别名]
# 或者: from past.builtins import cmp [as 别名]
def test_cmp(self):
        before = """
        assert cmp(1, 2) == -1
        assert cmp(2, 1) == 1
        """
        after = """
        from past.builtins import cmp
        assert cmp(1, 2) == -1
        assert cmp(2, 1) == 1
        """
        self.convert_check(before, after, stages=(1, 2), ignore_imports=False) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:13,代码来源:test_futurize.py

示例6: sortByCloneSize

# 需要导入模块: from past import builtins [as 别名]
# 或者: from past.builtins import cmp [as 别名]
def sortByCloneSize(self):
        def f(a,b):
            return cmp(b.getMaxCoveredLineNumbersCount(), a.getMaxCoveredLineNumbersCount())
        self._clones.sort(f) 
开发者ID:jlachowski,项目名称:clonedigger,代码行数:6,代码来源:html_report.py

示例7: __cmp__

# 需要导入模块: from past import builtins [as 别名]
# 或者: from past.builtins import cmp [as 别名]
def __cmp__(self, other):
                keys = list(self._data.keys())
                okeys = list(other._data.keys())
                keys.sort()
                okeys.sort()
                return cmp(keys, okeys) 
开发者ID:jlachowski,项目名称:clonedigger,代码行数:8,代码来源:compat.py

示例8: sorted

# 需要导入模块: from past import builtins [as 别名]
# 或者: from past.builtins import cmp [as 别名]
def sorted(iterable, cmp=None, key=None, reverse=False):
        original = list(iterable)
        if key:
            l2 = [(key(elt), index) for index, elt in enumerate(original)]
        else:
            l2 = original
        l2.sort(cmp)
        if reverse:
            l2.reverse()
        if key:
            return [original[index] for elt, index in l2]
        return l2 
开发者ID:jlachowski,项目名称:clonedigger,代码行数:14,代码来源:compat.py

示例9: my_lstrcmp

# 需要导入模块: from past import builtins [as 别名]
# 或者: from past.builtins import cmp [as 别名]
def my_lstrcmp(jitter, funcname, get_str):
    ret_ad, args = jitter.func_args_stdcall(["ptr_str1", "ptr_str2"])
    s1 = get_str(args.ptr_str1)
    s2 = get_str(args.ptr_str2)
    log.info("Compare %r with %r", s1, s2)
    jitter.func_ret_stdcall(ret_ad, cmp(s1, s2)) 
开发者ID:cea-sec,项目名称:miasm,代码行数:8,代码来源:win_api_x86_32.py

示例10: msvcrt_wcscmp

# 需要导入模块: from past import builtins [as 别名]
# 或者: from past.builtins import cmp [as 别名]
def msvcrt_wcscmp(jitter):
    ret_ad, args = jitter.func_args_cdecl(["ptr_str1", "ptr_str2"])
    s1 = get_win_str_w(jitter, args.ptr_str1)
    s2 = get_win_str_w(jitter, args.ptr_str2)
    log.debug("%s('%s','%s')" % (whoami(), s1, s2))
    jitter.func_ret_cdecl(ret_ad, cmp(s1, s2)) 
开发者ID:cea-sec,项目名称:miasm,代码行数:8,代码来源:win_api_x86_32.py

示例11: msvcrt__wcsicmp

# 需要导入模块: from past import builtins [as 别名]
# 或者: from past.builtins import cmp [as 别名]
def msvcrt__wcsicmp(jitter):
    ret_ad, args = jitter.func_args_cdecl(["ptr_str1", "ptr_str2"])
    s1 = get_win_str_w(jitter, args.ptr_str1)
    s2 = get_win_str_w(jitter, args.ptr_str2)
    log.debug("%s('%s','%s')" % (whoami(), s1, s2))
    jitter.func_ret_cdecl(ret_ad, cmp(s1.lower(), s2.lower())) 
开发者ID:cea-sec,项目名称:miasm,代码行数:8,代码来源:win_api_x86_32.py

示例12: msvcrt__wcsnicmp

# 需要导入模块: from past import builtins [as 别名]
# 或者: from past.builtins import cmp [as 别名]
def msvcrt__wcsnicmp(jitter):
    ret_ad, args = jitter.func_args_cdecl(["ptr_str1", "ptr_str2", "count"])
    s1 = get_win_str_w(jitter, args.ptr_str1)
    s2 = get_win_str_w(jitter, args.ptr_str2)
    log.debug("%s('%s','%s',%d)" % (whoami(), s1, s2, args.count))
    jitter.func_ret_cdecl(ret_ad, cmp(s1.lower()[:args.count], s2.lower()[:args.count])) 
开发者ID:cea-sec,项目名称:miasm,代码行数:8,代码来源:win_api_x86_32.py

示例13: msvcrt_memcmp

# 需要导入模块: from past import builtins [as 别名]
# 或者: from past.builtins import cmp [as 别名]
def msvcrt_memcmp(jitter):
    ret_ad, args = jitter.func_args_cdecl(['ps1', 'ps2', 'size'])
    s1 = jitter.vm.get_mem(args.ps1, args.size)
    s2 = jitter.vm.get_mem(args.ps2, args.size)
    ret = cmp(s1, s2)
    jitter.func_ret_cdecl(ret_ad, ret) 
开发者ID:cea-sec,项目名称:miasm,代码行数:8,代码来源:win_api_x86_32.py

示例14: __cmp__

# 需要导入模块: from past import builtins [as 别名]
# 或者: from past.builtins import cmp [as 别名]
def __cmp__(self, other):
        """Compare a Key with another object for sorting purposes.

        Args:
            other (object): The object to compare with

        Returns:
            int: (-1 if self < other, 0 if self == other, 1 if self > other)
        """
        # pylint: disable=protected-access
        if isinstance(other, Key):
            return (cmp(self._object_kind, other._object_kind) or
                    cmp(self._object_path_tuple, other._object_path_tuple))
        return cmp(self, other) 
开发者ID:forseti-security,项目名称:forseti-security,代码行数:16,代码来源:key.py

示例15: create_orderbook_table

# 需要导入模块: from past import builtins [as 别名]
# 或者: from past.builtins import cmp [as 别名]
def create_orderbook_table(self, btc_unit, rel_unit):
        result = ''
        try:
            self.taker.dblock.acquire(True)
            rows = self.taker.db.execute('SELECT * FROM orderbook;').fetchall()
        finally:
            self.taker.dblock.release()
        if not rows:
            return 0, result
        #print("len rows before filter: " + str(len(rows)))
        rows = [o for o in rows if o["ordertype"] in filtered_offername_list]
        order_keys_display = (('ordertype', ordertype_display),
                              ('counterparty', do_nothing), ('oid', order_str),
                              ('cjfee', cjfee_display), ('txfee', satoshi_to_unit),
                              ('minsize', satoshi_to_unit),
                              ('maxsize', satoshi_to_unit))

        # somewhat complex sorting to sort by cjfee but with swabsoffers on top

        def orderby_cmp(x, y):
            if x['ordertype'] == y['ordertype']:
                return cmp(Decimal(x['cjfee']), Decimal(y['cjfee']))
            return cmp(offername_list.index(x['ordertype']),
                       offername_list.index(y['ordertype']))

        for o in sorted(rows, key=cmp_to_key(orderby_cmp)):
            result += ' <tr>\n'
            for key, displayer in order_keys_display:
                result += '  <td>' + displayer(o[key], o, btc_unit,
                                               rel_unit) + '</td>\n'
            result += ' </tr>\n'
        return len(rows), result 
开发者ID:JoinMarket-Org,项目名称:joinmarket-clientserver,代码行数:34,代码来源:ob-watcher.py


注:本文中的past.builtins.cmp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。