本文整理汇总了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)