本文整理匯總了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)
示例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))
示例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)
示例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)