當前位置: 首頁>>代碼示例>>Python>>正文


Python operator.__getitem__方法代碼示例

本文整理匯總了Python中operator.__getitem__方法的典型用法代碼示例。如果您正苦於以下問題:Python operator.__getitem__方法的具體用法?Python operator.__getitem__怎麽用?Python operator.__getitem__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在operator的用法示例。


在下文中一共展示了operator.__getitem__方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testAccess

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import __getitem__ [as 別名]
def testAccess(self):
        A = matrix([2, 3])
        self.failUnlessEqual(str(A), "unnamed_matrix{=((unnamed_matrix[0, 0], unnamed_matrix[0, 1], unnamed_matrix[0, 2]), (unnamed_matrix[1, 0], unnamed_matrix[1, 1], unnamed_matrix[1, 2]))}")
        self.failUnlessEqual(A[0, 0].is_set(), 0)
        self.failUnlessEqual(A[1, 0].is_set(), 0)
        self.failUnlessRaises(IndexError, operator.__getitem__, A, (2, 0))
        self.failUnlessEqual(A[0, 1].is_set(), 0)
        self.failUnlessEqual(A[1, 1].is_set(), 0)
        self.failUnlessEqual(A[0, 2].is_set(), 0)
        self.failUnlessEqual(A[1, 2].is_set(), 0)
        self.failUnlessRaises(IndexError, operator.__getitem__, A, (0, 3))
        A[0, 0].set(1)
        self.failUnlessEqual(A[0, 0].is_set(), 1)
        self.failUnlessEqual(A[0, 1].is_set(), 0)
        self.failUnlessEqual(A[1, 0].is_set(), 0)
        self.failUnlessAlmostEqual(A[0, 0].get(), 1.0)
        self.failUnlessAlmostEqual(float(A[0, 0]), 1.0) 
開發者ID:pyx-project,項目名稱:pyx,代碼行數:19,代碼來源:test_solve.py

示例2: decompile

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import __getitem__ [as 別名]
def decompile(cls, ea):
        '''(UNSTABLE) Returns the decompiled code of the basic block at the address `ea`.'''
        source = idaapi.decompile(ea)

        res = itertools.imap(functools.partial(operator.__getitem__, source.eamap), cls.iterate(ea))
        res = itertools.chain(*res)
        formatted = reduce(lambda t, c: t if t[-1].ea == c.ea else t+[c], res, [next(res)])

        res = []
        # FIXME: This has been pretty damn unstable in my tests.
        try:
            for fmt in formatted:
                res.append( fmt.print1(source.__deref__()) )
        except TypeError: pass
        res = itertools.imap(idaapi.tag_remove, res)
        return '\n'.join(map(utils.string.of, res)) 
開發者ID:arizvisa,項目名稱:ida-minsc,代碼行數:18,代碼來源:function.py

示例3: testIReadMapping

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import __getitem__ [as 別名]
def testIReadMapping(self, inst, state, absent):
    for key in state:
        self.assertEqual(inst[key], state[key])
        self.assertEqual(inst.get(key, None), state[key])
        self.assertTrue(key in inst)

    for key in absent:
        self.assertEqual(inst.get(key, None), None)
        self.assertEqual(inst.get(key), None)
        self.assertEqual(inst.get(key, self), self)
        self.assertRaises(KeyError, __getitem__, inst, key) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:13,代碼來源:basemapping.py

示例4: testIReadMapping

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import __getitem__ [as 別名]
def testIReadMapping(self, inst, state, absent):
    for key in state:
        self.assertEqual(inst[key], state[key])
        self.assertEqual(inst.get(key, None), state[key])
        self.failUnless(key in inst)

    for key in absent:
        self.assertEqual(inst.get(key, None), None)
        self.assertEqual(inst.get(key), None)
        self.assertEqual(inst.get(key, self), self)
        self.assertRaises(KeyError, __getitem__, inst, key) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:13,代碼來源:basemapping.py


注:本文中的operator.__getitem__方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。