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


Python __builtin__.xrange方法代码示例

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


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

示例1: xrange

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import xrange [as 别名]
def xrange(*args):
        """Coconut uses Python 3 "range" instead of Python 2 "xrange"."""
        raise _coconut.NameError('Coconut uses Python 3 "range" instead of Python 2 "xrange"') 
开发者ID:evhub,项目名称:pyprover,代码行数:5,代码来源:__coconut__.py

示例2: test_init_only_two_tiles

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import xrange [as 别名]
def test_init_only_two_tiles(self):
        t = 0
        for x in xrange(Board.SIZE):
            for y in xrange(Board.SIZE):
                c = self.b.cells[y][x]
                if not c == 0:
                    t += 1
                else:
                    self.assertEqual(c, 0, 'board[%d][%d] should be 0' % (y, x))

        self.assertEqual(t, 2) 
开发者ID:Nicola17,项目名称:term2048-AI,代码行数:13,代码来源:test_board.py

示例3: test_filled

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import xrange [as 别名]
def test_filled(self):
        self.b.cells = [[1]*Board.SIZE for _ in xrange(Board.SIZE)]
        self.assertTrue(self.b.filled())

    # == .addTile == # 
开发者ID:Nicola17,项目名称:term2048-AI,代码行数:7,代码来源:test_board.py

示例4: test_getCol

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import xrange [as 别名]
def test_getCol(self):
        s = 4
        b = Board(size=s)
        l = [42, 17, 12, 3]
        b.cells = [[l[i], 4, 1, 2] for i in xrange(s)]
        self.assertSequenceEqual(b.getCol(0), l)

    # == .setLine == # 
开发者ID:Nicola17,项目名称:term2048-AI,代码行数:10,代码来源:test_board.py

示例5: setUp

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import xrange [as 别名]
def setUp(self):
        try:
            self.xr = __builtin__.xrange
            delattr(__builtin__, 'xrange')
        except AttributeError:
            self.xr = None
        helpers.reload(board) 
开发者ID:Nicola17,项目名称:term2048-AI,代码行数:9,代码来源:test_board.py

示例6: tearDown

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import xrange [as 别名]
def tearDown(self):
        __builtin__.xrange = self.xr 
开发者ID:Nicola17,项目名称:term2048-AI,代码行数:4,代码来源:test_board.py

示例7: xrange

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import xrange [as 别名]
def xrange(*args, **kwargs):
    major_version = sys.version_info.major
    if major_version == 2:
        import __builtin__
        return __builtin__.xrange(*args, **kwargs)
    elif major_version >= 3:
        import builtins
        return builtins.range(*args, **kwargs)
    else:
        raise RuntimeError("Unsupported version of Python.") 
开发者ID:dstein64,项目名称:pyfms,代码行数:12,代码来源:utils.py

示例8: test_pickle_python2_python3

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import xrange [as 别名]
def test_pickle_python2_python3():
    # Test that loading object arrays saved on Python 2 works both on
    # Python 2 and Python 3 and vice versa
    data_dir = os.path.join(os.path.dirname(__file__), 'data')

    if sys.version_info[0] >= 3:
        xrange = range
    else:
        import __builtin__
        xrange = __builtin__.xrange

    expected = np.array([None, xrange, u'\u512a\u826f',
                         b'\xe4\xb8\x8d\xe8\x89\xaf'],
                        dtype=object)

    for fname in ['py2-objarr.npy', 'py2-objarr.npz',
                  'py3-objarr.npy', 'py3-objarr.npz']:
        path = os.path.join(data_dir, fname)

        for encoding in ['bytes', 'latin1']:
            data_f = np.load(path, encoding=encoding)
            if fname.endswith('.npz'):
                data = data_f['x']
                data_f.close()
            else:
                data = data_f

            if sys.version_info[0] >= 3:
                if encoding == 'latin1' and fname.startswith('py2'):
                    assert_(isinstance(data[3], str))
                    assert_array_equal(data[:-1], expected[:-1])
                    # mojibake occurs
                    assert_array_equal(data[-1].encode(encoding), expected[-1])
                else:
                    assert_(isinstance(data[3], bytes))
                    assert_array_equal(data, expected)
            else:
                assert_array_equal(data, expected)

        if sys.version_info[0] >= 3:
            if fname.startswith('py2'):
                if fname.endswith('.npz'):
                    data = np.load(path)
                    assert_raises(UnicodeError, data.__getitem__, 'x')
                    data.close()
                    data = np.load(path, fix_imports=False, encoding='latin1')
                    assert_raises(ImportError, data.__getitem__, 'x')
                    data.close()
                else:
                    assert_raises(UnicodeError, np.load, path)
                    assert_raises(ImportError, np.load, path,
                                  encoding='latin1', fix_imports=False) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:54,代码来源:test_format.py

示例9: test_pickle_python2_python3

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import xrange [as 别名]
def test_pickle_python2_python3():
    # Test that loading object arrays saved on Python 2 works both on
    # Python 2 and Python 3 and vice versa
    data_dir = os.path.join(os.path.dirname(__file__), 'data')

    if sys.version_info[0] >= 3:
        xrange = range
    else:
        import __builtin__
        xrange = __builtin__.xrange

    expected = np.array([None, xrange, u'\u512a\u826f',
                         b'\xe4\xb8\x8d\xe8\x89\xaf'],
                        dtype=object)

    for fname in ['py2-objarr.npy', 'py2-objarr.npz',
                  'py3-objarr.npy', 'py3-objarr.npz']:
        path = os.path.join(data_dir, fname)

        for encoding in ['bytes', 'latin1']:
            data_f = np.load(path, allow_pickle=True, encoding=encoding)
            if fname.endswith('.npz'):
                data = data_f['x']
                data_f.close()
            else:
                data = data_f

            if sys.version_info[0] >= 3:
                if encoding == 'latin1' and fname.startswith('py2'):
                    assert_(isinstance(data[3], str))
                    assert_array_equal(data[:-1], expected[:-1])
                    # mojibake occurs
                    assert_array_equal(data[-1].encode(encoding), expected[-1])
                else:
                    assert_(isinstance(data[3], bytes))
                    assert_array_equal(data, expected)
            else:
                assert_array_equal(data, expected)

        if sys.version_info[0] >= 3:
            if fname.startswith('py2'):
                if fname.endswith('.npz'):
                    data = np.load(path, allow_pickle=True)
                    assert_raises(UnicodeError, data.__getitem__, 'x')
                    data.close()
                    data = np.load(path, allow_pickle=True, fix_imports=False,
                                   encoding='latin1')
                    assert_raises(ImportError, data.__getitem__, 'x')
                    data.close()
                else:
                    assert_raises(UnicodeError, np.load, path,
                                  allow_pickle=True)
                    assert_raises(ImportError, np.load, path,
                                  allow_pickle=True, fix_imports=False,
                                  encoding='latin1') 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:57,代码来源:test_format.py

示例10: iwait

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import xrange [as 别名]
def iwait(objects, timeout=None, count=None):
    """
    Iteratively yield *objects* as they are ready, until all (or *count*) are ready
    or *timeout* expired.

    :param objects: A sequence (supporting :func:`len`) containing objects
        implementing the wait protocol (rawlink() and unlink()).
    :keyword int count: If not `None`, then a number specifying the maximum number
        of objects to wait for. If ``None`` (the default), all objects
        are waited for.
    :keyword float timeout: If given, specifies a maximum number of seconds
        to wait. If the timeout expires before the desired waited-for objects
        are available, then this method returns immediately.

    .. seealso:: :func:`wait`

    .. versionchanged:: 1.1a1
       Add the *count* parameter.
    .. versionchanged:: 1.1a2
       No longer raise :exc:`LoopExit` if our caller switches greenlets
       in between items yielded by this function.
    """
    # QQQ would be nice to support iterable here that can be generated slowly (why?)
    if objects is None:
        yield get_hub().join(timeout=timeout)
        return

    count = len(objects) if count is None else min(count, len(objects))
    waiter = _MultipleWaiter()
    switch = waiter.switch

    if timeout is not None:
        timer = get_hub().loop.timer(timeout, priority=-1)
        timer.start(switch, _NONE)

    try:
        for obj in objects:
            obj.rawlink(switch)

        for _ in xrange(count):
            item = waiter.get()
            waiter.clear()
            if item is _NONE:
                return
            yield item
    finally:
        if timeout is not None:
            timer.stop()
        for obj in objects:
            unlink = getattr(obj, 'unlink', None)
            if unlink:
                try:
                    unlink(switch)
                except:
                    traceback.print_exc() 
开发者ID:leancloud,项目名称:satori,代码行数:57,代码来源:hub.py


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