Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:next()无法识别_Python_Next - Fatal编程技术网

Python:next()无法识别

Python:next()无法识别,python,next,Python,Next,当我从 下一步(迭代器[,默认]) 因此,是的,它确实需要2.6版。尽管您可以在2.6中调用ByteIter.next()。但是,不建议这样做,因为该方法在Python3中已重命名为next()。直到Python2.6才添加 然而,有一个解决办法。您可以在Python 2 iterables上调用.next(): try: ByteIter.next() << 8 except StopIteration: pass 这与Python 2.6版本的工作原理类似: &

当我从

下一步(迭代器[,默认])


因此,是的,它确实需要2.6版。

尽管您可以在2.6中调用ByteIter.next()。但是,不建议这样做,因为该方法在Python3中已重命名为next()。

直到Python2.6才添加

然而,有一个解决办法。您可以在Python 2 iterables上调用
.next()

try:
    ByteIter.next() << 8
except StopIteration:
    pass
这与Python 2.6版本的工作原理类似:

>>> next(iter([]), 'stopped')
'stopped'
>>> next(iter([]))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in next
StopIteration
下一步(iter([]),“停止”) “停止” >>>下一个(国际热核实验堆([])) 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 文件“”,第3行,在下一页 停止迭代 它是在py2.6中引入的
_sentinel = object()
def next(iterable, default=_sentinel):
    try:
        return iterable.next()
    except StopIteration:
        if default is _sentinel:
            raise
        return default
>>> next(iter([]), 'stopped')
'stopped'
>>> next(iter([]))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in next
StopIteration