[IPython-dev] Re: Changes to Notebook Format

Fernando Perez Fernando.Perez at colorado.edu
Wed Jul 27 00:44:40 CDT 2005


Robert Kern wrote:
> Tzanko Matev wrote:
> 
>>Hi all,
>>
>>I found other problems with the current format. It is entirely possible
>>that a single input has several outputs, and prints to stdout and/or
>>stderr several times. Take for examlpe the following code. 
>>
>>In [1]: if True:
>>   ...:     1
>>   ...:     print 'foo'
>>   ...:     2
>>   ...:     print 'bar'
>>   ...:
>>Out[1]: 1
>>foo
>>Out[1]: 2
>>bar
> 
> 
> I've never run into a case where I actually want to see multiple 
> Out[1]'s. It's usually in the middle of a for loop and I've forgotten 
> that a function returns an object that I don't really need to see (e.g. 
> pylab.plot()). Since only the last one actually goes into the output 
> cache (that is, is accessible for later use via Out[1]), I'm not 
> convinced that printing multiple Out[1]'s is useful. If I really want to 
> see something in the middle of a loop, I'll print it.

Here's an even worse example:

In [3]: for i in range(3):
    ...:     print 'passing...'
    ...:     i
    ...:
passing...
Out[3]: 0
passing...
Out[3]: 1
passing...
Out[3]: 2

The multiple Out[] behavior is really mostly an implementation accident, not a 
design feature.  I'd be willing to consider it a bug, in the sense that naked 
expressions in compound statements should not really be treated as return 
valuues.  I think the example above should simply print 'passing...' three 
times, and NOT generate an Out[] cell at all.

> As for having stdout cells interleaved with other types of output cells, 
> I think that's going to be pretty hard. You'd have to collect the output 
> from each statement separately. I'm of the opinion that you should just 
> collect one each of stdout and stderr.

Yup.

Cheers,

f




More information about the IPython-dev mailing list