[IPython-User] output of multiple statements?

Fernando Perez fperez.net@gmail....
Sun Jan 22 16:32:11 CST 2012


2012/1/22 Zoltán Vörös <zvoros@gmail.com>:
> Now, my question is whether this has been considered, or there is a very
> fundamental reason for not changing this, even in the multiline
> qtconsole or the notebook. I can very well imagine that it might not be
> trivial to sort out the outputs of all statements, and then one just
> waits for the last one...

To give you a bit more context (Thomas' reply was spot-on), we did
think a lot about this. The problem is that there are many common
function calls that return values but that we make for their side
effects, especially with plotting.  So if we compiled all statements
in interactive mode, it would mean that something like

for i in range(10):
  plot_something(...)

would produce 10 separate Out[] points.  But obviously for single
statements you want to get an output, so we sought a compromise and
ended up with the current behavior: only the last statement is treated
as something interactive, and anything above it is compiled in 'exec'
mode.

The best way to think of a cell is like a 'little script': use
explicit print statements for anything for which you need to see the
value, and consider the 'last statement produces output' as a
convenience shortcut.

We're happy to get more feedback on this, because we realize it's hard
to find the right balance.  We thought for a long time about it, and
considered how both mathematica and sage behave before arriving at our
current model.  Honestly I like our solution, but user feedback on
this front is always very valuable.

Cheers,

f


More information about the IPython-User mailing list