【发布时间】:2016-12-28 08:01:35
【问题描述】:
我发现了这个关于 Python 中迭代器行为的问题:
Python list iterator behavior and next(iterator)
当我输入代码时:
a = iter(list(range(10)))
for i in a:
print a
next(a)
进入它返回的jupyter-qtconsole:
0
2
4
6
8
正如 Martijn Pieters 所说,当解释器没有回应对 next(a) 的调用时应该这样做。
但是,当我在 Bash 解释器和 IDLE 中再次运行相同的代码时,打印的代码:
0
1
2
3
4
5
6
7
8
9
到控制台。
我运行了代码:
import platform
platform.python_implementation()
在所有三个环境中,他们都说我跑了'CPython'。
那么为什么 QtConsole 会抑制 next(a) 调用,而 IDLE 和 Bash 不会呢?
如果有帮助,我将在 Mac OSX 上运行 Python 2.7.9 并使用 Anaconda 发行版。
【问题讨论】:
标签: python interpreter jupyter python-internals