[IPython-dev] Re: Changes to Notebook Format

Tzanko Matev tsanko at gmail.com
Tue Jul 26 07:50:44 CDT 2005


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

To fix that we should allow several elements of types <output>, <stdout>
and <stderr> to be included in a cell. Also we want to keep the order in
which they were produced. I can see two ways to do this. 

One way is to add an 'order' attribute to all the <output>, <stdout> and
<stderr> elements in the cell. Also in the <ipython-block> element all
the <ipython-output>, <ipython-stdout> and <ipython-stderr> elements
should have this attribute. Then we won't need separate tags in
<ipython-block> for all types of  output, because the 'number' and
'order' attributes will be enough to decide which output element should
be displayed at the given position.

Another way is to use the order in which the elements in the cell are
written. We can state that the first one or two elements must be of type
<input> and <special-input>. The elements after them will be of types
<output>, <stdout>, <stderr>, <figure>, etc. and the order in which they
were produced by the input corresponds to the order in which they are
written in the cell. Then in <ipython-block> we can get rid of all the
different tags and replace them with tags like <element number='1'
cellnumber='2'/>  which will point to the second element in the first
cell in the log.

Right now, I'm not really sure which one is better. The second way will
probably be faster to run, because I will be able to work with a cell
like a list and not use the find() method or XPath to retrieve elements.
What do you think?

Best,
tzanko




More information about the IPython-dev mailing list