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


Python operator.getslice方法代码示例

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


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

示例1: test_getslice

# 需要导入模块: import operator [as 别名]
# 或者: from operator import getslice [as 别名]
def test_getslice(self):
        a = range(10)
        self.assertRaises(TypeError, operator.getslice)
        self.assertRaises(TypeError, operator.getslice, a, None, None)
        self.assertTrue(operator.getslice(a, 4, 6) == [4, 5])
        b = operator.getslice(a, 0, test_support.MAX_Py_ssize_t)
        self.assertTrue(b == a) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_operator.py

示例2: __getslice__

# 需要导入模块: import operator [as 别名]
# 或者: from operator import getslice [as 别名]
def __getslice__(self, key):
        return Expression((self, key), operator.getslice) 
开发者ID:ebranca,项目名称:owasp-pysec,代码行数:4,代码来源:expr.py

示例3: test_getslice

# 需要导入模块: import operator [as 别名]
# 或者: from operator import getslice [as 别名]
def test_getslice(self):
        a = range(10)
        self.failUnlessRaises(TypeError, operator.getslice)
        self.failUnlessRaises(TypeError, operator.getslice, a, None, None)
        self.failUnless(operator.getslice(a, 4, 6) == [4, 5])
        b = operator.getslice(a, 0, test_support.MAX_Py_ssize_t)
        self.assert_(b == a) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:9,代码来源:test_operator.py

示例4: __getslice__

# 需要导入模块: import operator [as 别名]
# 或者: from operator import getslice [as 别名]
def __getslice__(self, *args, **kw):
        from operator import getslice
        return getslice(self.val, *args, **kw) 
开发者ID:graik,项目名称:biskit,代码行数:5,代码来源:Density.py

示例5: test_simple

# 需要导入模块: import operator [as 别名]
# 或者: from operator import getslice [as 别名]
def test_simple(self):
        # create classes holding simple numeric types, and check
        # various properties.

        init = range(15, 25)

        for fmt in formats:
            alen = len(init)
            int_array = ARRAY(fmt, alen)

            ia = int_array(*init)
            # length of instance ok?
            self.assertEqual(len(ia), alen)

            # slot values ok?
            values = [ia[i] for i in range(alen)]
            self.assertEqual(values, init)

            # out-of-bounds accesses should be caught
            with self.assertRaises(IndexError): ia[alen]
            with self.assertRaises(IndexError): ia[-alen-1]

            # change the items
            from operator import setitem
            new_values = range(42, 42+alen)
            [setitem(ia, n, new_values[n]) for n in range(alen)]
            values = [ia[i] for i in range(alen)]
            self.assertEqual(values, new_values)

            # are the items initialized to 0?
            ia = int_array()
            values = [ia[i] for i in range(alen)]
            self.assertEqual(values, [0] * alen)

            # Too many initializers should be caught
            self.assertRaises(IndexError, int_array, *range(alen*2))

        CharArray = ARRAY(c_char, 3)

        ca = CharArray("a", "b", "c")

        # Should this work? It doesn't:
        # CharArray("abc")
        self.assertRaises(TypeError, CharArray, "abc")

        self.assertEqual(ca[0], "a")
        self.assertEqual(ca[1], "b")
        self.assertEqual(ca[2], "c")
        self.assertEqual(ca[-3], "a")
        self.assertEqual(ca[-2], "b")
        self.assertEqual(ca[-1], "c")

        self.assertEqual(len(ca), 3)

        # slicing is now supported, but not extended slicing (3-argument)!
        from operator import getslice, delitem
        self.assertRaises(TypeError, getslice, ca, 0, 1, -1)

        # cannot delete items
        self.assertRaises(TypeError, delitem, ca, 0) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:62,代码来源:test_arrays.py

示例6: test_simple

# 需要导入模块: import operator [as 别名]
# 或者: from operator import getslice [as 别名]
def test_simple(self):
        # create classes holding simple numeric types, and check
        # various properties.

        init = range(15, 25)

        for fmt in formats:
            alen = len(init)
            int_array = ARRAY(fmt, alen)

            ia = int_array(*init)
            # length of instance ok?
            self.assertEqual(len(ia), alen)

            # slot values ok?
            values = [ia[i] for i in range(len(init))]
            self.assertEqual(values, init)

            # change the items
            from operator import setitem
            new_values = range(42, 42+alen)
            [setitem(ia, n, new_values[n]) for n in range(alen)]
            values = [ia[i] for i in range(len(init))]
            self.assertEqual(values, new_values)

            # are the items initialized to 0?
            ia = int_array()
            values = [ia[i] for i in range(len(init))]
            self.assertEqual(values, [0] * len(init))

            # Too many initializers should be caught
            self.assertRaises(IndexError, int_array, *range(alen*2))

        CharArray = ARRAY(c_char, 3)

        ca = CharArray("a", "b", "c")

        # Should this work? It doesn't:
        # CharArray("abc")
        self.assertRaises(TypeError, CharArray, "abc")

        self.assertEqual(ca[0], "a")
        self.assertEqual(ca[1], "b")
        self.assertEqual(ca[2], "c")
        self.assertEqual(ca[-3], "a")
        self.assertEqual(ca[-2], "b")
        self.assertEqual(ca[-1], "c")

        self.assertEqual(len(ca), 3)

        # slicing is now supported, but not extended slicing (3-argument)!
        from operator import getslice, delitem
        self.assertRaises(TypeError, getslice, ca, 0, 1, -1)

        # cannot delete items
        self.assertRaises(TypeError, delitem, ca, 0) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:58,代码来源:test_arrays.py


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