Why is QtConsole echo next ()?

I found this question about iterator behavior in Python:

Python and next (iterator) naming names

When I typed the code:

a = iter(list(range(10))) for i in a: print a next(a) 

to jupyter-qtconsole return value:

 0 2 4 6 8 

just like Martin Pieter said when the interpreter does not answer the next(a) call.

However, when I ran the code again in my Bash and IDLE interpreter, the code printed:

 0 1 2 3 4 5 6 7 8 9 

to the console.

I ran the code:

 import platform platform.python_implementation() 

in all three environments, and they all said that I ran 'CPython' .

So why does QtConsole suppress the next(a) call when IDLE and Bash are down?

If this helps, I run Python 2.7.9 on Mac OSX and use the Anaconda distribution.

+7
python python-internals interpreter jupyter
source share
1 answer

This is just the choice that the IPython developers (on whom QtConsole is based) are made about what should be repeated by the user.

In particular, InteractiveShell uses the run_ast_nodes class run_ast_nodes the default is defined using interactivity='last_expr' . The documentation for this attribute reads:

 interactivity : str 'all', 'last', 'last_expr' or 'none', specifying which nodes should be run interactively (displaying output from expressions). 'last_expr' will run the last node interactively only if it is an expression (ie expressions in loops or other blocks are not displayed. Other values for this parameter will raise a ValueError. 

As you can see: expressions in loops or other blocks are not displayed .

You can change this in the configuration files for IPython and make it work as your repl if you really need to. Point, that was just the preference that the designers made.

+3
source share

All Articles