當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。