Why doesn't QtConsole echo next()?

Jack St. Claire

I found this question about iterator behavior in Python:

Python list iterator behavior and next(iterator)

When I typed in the code:

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

into the jupyter-qtconsole it returned:

0
2
4
6
8

exactly as Martijn Pieters said it should when the interpreter doesn't echo the call to next(a).

However, when I ran the same the code again in my Bash interpreter and IDLE, 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 I ran 'CPython'.

So why does the QtConsole suppress the next(a) call when IDLE and Bash don't?

If it helps, I'm running Python 2.7.9 on Mac OSX and using the Anaconda distribution.

Dimitris Fasarakis Hilliard

This is just a choice the developers of IPython (on which the QtConsole is based) made regarding what should be echoed back to the user.

Specifically, in the InteractiveShell class that is used, function run_ast_nodes is, by default, defined with an interactivity='last_expr'. The documentation on this attribute states:

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 (i.e.
  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 config files for IPython and get it to work like your repl if you really need to. Point is, it was just a preference the designers made.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why doesn't "echo" show up in "ps"?

From Dev

Why doesn't this program echo any string?

From Dev

Why doesn't "make" echo anything?

From Dev

Why doesn't this program echo any string?

From Dev

Why doesn't "make" echo anything?

From Dev

why 'echo --help' doesn't give me help page of echo?

From Dev

why 'echo --help' doesn't give me help page of echo?

From Dev

Why doesn't @ECHO ON/OFF work within a batch file IF block?

From Dev

In Bash, why `x=100 echo $x` doesn't print anything?

From Dev

Why doesn't `FOO=42 echo "$FOO"` print 42 in Bash?

From Dev

Why doesn't the echo "Hello World!" statement work as expected?

From Dev

why doesn't echo test &>>file work on OS X

From Dev

Why doesn't bash/echo work in this CMake script?

From Dev

Why does print work with awk but echo doesn't?

From Dev

Why doesn't echo work in if / else-shorthand?

From Dev

Why doesn't alias foo='echo "This is a quote: \'"' work?

From Dev

why shell doesn't show anything after the command echo $VERSION

From Dev

Why doesn't `echo abc^H` just print `ab`?

From Dev

Why doesn't my simple echo command not work?

From Dev

Why doesn't echo php in css.php not work?

From Dev

Why doesn't this work: ~$ echo "trythis" | sh ./script.sh

From Dev

Why doesn't echo called as /bin/sh -c echo foo output anything?

From Dev

Why is IPython QtConsole not launching?

From Dev

Python - Why is the default value for next initialized if it doesn't get used?

From Dev

why getchar() doesn't get next value from input?

From Dev

Why doesn't the AI bool flag preserve through the next page?

From Dev

PHP echo doesn't echo certain output

From Dev

Function doesn't return but echo

From Dev

Alias for "echo $?" doesn't work

Related Related

HotTag

Archive